I'm trying to create code to auto detect a drop in VPN connection and general internet connection (as well as when it reconnects to both).
I've tried AddHandler with the VpnApiClass (every action in intellisense) and NetworkChange.NetworkAvailabilityChanged. NetworkChange.NetworkAvailabilityChanged works for internet dropping, but not if just the VPN drops.
'''''VB.NET:
Private Sub Main_Load(sender As Object, e as EventArgs) Handles MyBase.Load
Dim tmpVpn as New NpnApiClass
AddHandler tmpVpn.VpnStateNotification, AddressOf NetworkConnectionChanged
AddHandler tmpVpn.VpnEventAvailableNotification, AddressOf NetworkConnectionChanged
AddHandler NetworkChange.NetworkAvailabilityChanged, AddressOf NetworkConnectionChanged
End Sub
Private Sub NetworkConnectionChanged()
'''''Note: CommonElements is a dll file I'm referencing, function returns a boolean (True if connected, False if disconnected).
If Not CommonElements.isConnectedToNetwork_NetworkInterface() Then
Main.AddFiles.Enabled = False
Main.RemoveFiles.Enabled = False
Status.Text = "Disconnected"
Else
Main.AddFiles.Enabled = True
Main.RemoveFiles.Enabled = True
Status.Text = "Connected"
End If
End Sub
Expecting to see buttons on main form disable buttons and update the status label text when disconnected from VPN. Then enable buttons and update the status label text when reconnected to VPN. Instead it doesn't update anything short of pulling the ethernet cord from my laptop. No errors or unhandled exceptions.