J
John Wright
I have been trying to get my program to detect the network status of my
program. On program startup I have the following code
If My.Computer.Network.IsAvailable = true then
'do some gui updating
else
'do other updating
end if
This is in the load function of my form. Right now if I run my program
without the cable attached (windows pops up the message Network cable is
unplugged and exchange also complains), it still says the network is
connected.
I have tried using the application events to check the status and it never
fires. So I used the following code:
Private NetAvailHandler As NetworkAvailabilityChangedEventHandler
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
NetAvailHandler = New
NetworkAvailabilityChangedEventHandler(AddressOf
NetworkChange_NetworkAvailabilityChanged)
AddHandler NetworkChange.NetworkAvailabilityChanged, NetAvailHandler
End Sub
Private Sub NetworkChange_NetworkAvailabilityChanged(ByVal sender As
Object, ByVal e As NetworkAvailabilityEventArgs)
If Me.InvokeRequired Then
Invoke(NetAvailHandler, New Object() {sender, e})
Return
End If
End Sub
''' <summary>
''' updates the GUI according to network status
''' </summary>
''' <remarks></remarks>
Private Sub UpdateNetworkInfo()
If NetworkInterface.GetIsNetworkAvailable = False Then
tsNetworkStatus.Image = ImageList1.Images(1)
tsNetworkStatus.ToolTipText = "Network Offline"
Else
tsNetworkStatus.Image = ImageList1.Images(0)
tsNetworkStatus.ToolTipText = "Network Online"
End If
End Sub
And it too fails to fire this event. Am I missing something? Why can't my
..net programs check for these events? I have put breakpoints in these
locations to see if they are firing and erroring, but they don't fire.
Anyone have any suggestions?
program. On program startup I have the following code
If My.Computer.Network.IsAvailable = true then
'do some gui updating
else
'do other updating
end if
This is in the load function of my form. Right now if I run my program
without the cable attached (windows pops up the message Network cable is
unplugged and exchange also complains), it still says the network is
connected.
I have tried using the application events to check the status and it never
fires. So I used the following code:
Private NetAvailHandler As NetworkAvailabilityChangedEventHandler
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
NetAvailHandler = New
NetworkAvailabilityChangedEventHandler(AddressOf
NetworkChange_NetworkAvailabilityChanged)
AddHandler NetworkChange.NetworkAvailabilityChanged, NetAvailHandler
End Sub
Private Sub NetworkChange_NetworkAvailabilityChanged(ByVal sender As
Object, ByVal e As NetworkAvailabilityEventArgs)
If Me.InvokeRequired Then
Invoke(NetAvailHandler, New Object() {sender, e})
Return
End If
End Sub
''' <summary>
''' updates the GUI according to network status
''' </summary>
''' <remarks></remarks>
Private Sub UpdateNetworkInfo()
If NetworkInterface.GetIsNetworkAvailable = False Then
tsNetworkStatus.Image = ImageList1.Images(1)
tsNetworkStatus.ToolTipText = "Network Offline"
Else
tsNetworkStatus.Image = ImageList1.Images(0)
tsNetworkStatus.ToolTipText = "Network Online"
End If
End Sub
And it too fails to fire this event. Am I missing something? Why can't my
..net programs check for these events? I have put breakpoints in these
locations to see if they are firing and erroring, but they don't fire.
Anyone have any suggestions?