My.Computer.Network.NetworkAvailabilityChanged EventĀ 

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 _
)

Parameters

  • sender
    Required. The Object that raised the event.

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 My.Computer.Network.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 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 My.Application.DoEvents Method.

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 My.Application.NetworkAvailabilityChanged Event.

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.

Note

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 My.Computer.Network.IsAvailable Property to check for network availability.

Example

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 a Label named Label1. You must call the Handle_NetworkAvailabilityChanged method to initialize the label and hook up the event handler.

Requirements

Namespace: Microsoft.VisualBasic.Devices

Class: Network

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Availability by Project Type

Project type Available

Windows Application

Yes

Class Library

Yes

Console Application

Yes

Windows Control Library

Yes

Web Control Library

Yes

Windows Service

Yes

Web Site

Yes

Permissions

No permissions are required.

See Also

Reference

My.Computer.Network Object
My.Application.NetworkAvailabilityChanged Event
Microsoft.VisualBasic.Devices.NetworkAvailableEventArgs