Occurs when the network availability changes.
' Usage Public Sub MyComputerNetwork_NetworkAvailabilityChanged( _ ByVal sender As Object, _ ByVal e As Devices.NetworkAvailableEventArgs _ ) End Sub Sub Handle_NetworkAvailabilityChanged() AddHandler My.Computer.Network.NetworkAvailabilityChanged, _ AddressOf MyComputerNetwork_NetworkAvailabilityChanged End Sub ' Declaration Public Event NetworkAvailabilityChanged( _ ByVal sender As Object, _ ByVal e As Devices.NetworkAvailableEventArgs _ )
Required. The Object that raised the event.
Required. Aobject that contains information about the availability of the network.
An application raises the NetworkAvailabilityChanged event every time the availability of the network changes. You can use the e parameter to get the new state of the network connection. To get the current state of the network connection, use the .property of the
In a Windows Forms application, this event is raised on the application's main thread with the other user-interface events. This allows the event handler to directly access the application's user interface. However, if the application is busy handling another user-interface event when this event is raised, this event cannot be processed until the other event handler finishes or calls the.
You cannot use the Handles statement to handle the NetworkAvailabilityChanged event; you must use the AddHandler statement.
In Windows Forms applications, the My.Application object exposes a NetworkAvailabilityChanged event that provides the same functionality as this event, but you can handle it with the Handles statement. For more information, see.
Many network hubs provide a network connection, even if the hub is disconnected from a larger network. Consequently, for wired connections, this event indicates a change in the connection between the computer and a hub.
The NetworkAvailabilityChanged event is not raised by applications that run on Windows 95 and Windows 98 or by applications that are run on Windows 2000 by a non-administrator. If your application might run on those platforms, use theto check for network availability.
This example uses the My.Computer.Network.NetworkAvailabilityChanged event to update the user interface of a form or control.
Private Sub DisplayAvailability(ByVal available As Boolean) Label1.Text = available.ToString End Sub Private Sub MyComputerNetwork_NetworkAvailabilityChanged( _ ByVal sender As Object, _ ByVal e As Devices.NetworkAvailableEventArgs) DisplayAvailability(e.IsNetworkAvailable) End Sub Private Sub Handle_NetworkAvailabilityChanged() AddHandler My.Computer.Network.NetworkAvailabilityChanged, _ AddressOf MyComputerNetwork_NetworkAvailabilityChanged DisplayAvailability(My.Computer.Network.IsAvailable) End Sub
This code should to be in a form or control that has anamed Label1. You must call the Handle_NetworkAvailabilityChanged method to initialize the label and hook up the event handler.