I am showcasing whether someone's connected via Always-On VPN - green = connected, red = disconnected. However, this only works when the application has started and I would like for it to continuously update the color of the label, if it suddenly disconnects and when you connect it again
Here's the code:
public bool CheckForVPNInterface()
{
if (NetworkInterface.GetIsNetworkAvailable())
{
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface networkInterfaces in interfaces)
{
if (networkInterfaces.Description.Contains("Always-On VPN") && networkInterfaces.OperationalStatus == OperationalStatus.Up)
{
Label_Connection.BackColor = Color.Green;
Button_ConnectVPN.Text = "Disconnect";
return true;
}
else
{
Label_Connection.BackColor = Color.Red;
Button_ConnectVPN.Text = "Connect";
}
}
}
return false;
}
Thanks in advance!