Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Network::NetworkAvailabilityChanged Event

 

Occurs when the network availability changes.

Namespace:   Microsoft.VisualBasic.Devices
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public:
event NetworkAvailableEventHandler^ NetworkAvailabilityChanged {
	void add(NetworkAvailableEventHandler^ value);
	void remove(NetworkAvailableEventHandler^ value);
}

An application raises the NetworkAvailabilityChanged event every time the availability of the network changes. You can use the IsNetworkAvailable property of the e parameter to get the new state of the network connection. To get the current state of the network connection, use the IsAvailable property.

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 access directly 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 DoEvents method.

You cannot use the Handles statement to handle the NetworkAvailabilityChanged event; you must use the AddHandler statement.

In Windows Forms applications, the MyApplication object exposes a NetworkAvailabilityChanged event that provides the same functionality as this event, but you can handle it with the Handles statement.

System_CAPS_noteNote

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.

System_CAPS_noteNote

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 the IsAvailable property.

This example uses the My.Computer.Network.NetworkAvailabilityChanged event to update the user interface of a form or control.

This code should to be in a form or control that has a Label named Label1.

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

.NET Framework
Available since 2.0
Return to top
Show:
© 2017 Microsoft