ערוך

שתף באמצעות


Network.NetworkAvailabilityChanged Event

Definition

Occurs when the network availability changes.

public:
 event Microsoft::VisualBasic::Devices::NetworkAvailableEventHandler ^ NetworkAvailabilityChanged;
public event Microsoft.VisualBasic.Devices.NetworkAvailableEventHandler NetworkAvailabilityChanged;
member this.NetworkAvailabilityChanged : Microsoft.VisualBasic.Devices.NetworkAvailableEventHandler 
Public Custom Event NetworkAvailabilityChanged As NetworkAvailableEventHandler 

Event Type

Examples

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(available As Boolean)
    Label1.Text = available.ToString
End Sub

Private Sub MyComputerNetwork_NetworkAvailabilityChanged(
    sender As Object,
    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

Remarks

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.

Note

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.

Applies to

See also