Export (0) Print
Expand All

WindowsFormsApplicationBase.NetworkAvailabilityChanged Event

Occurs when the network availability changes.

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

public event NetworkAvailableEventHandler NetworkAvailabilityChanged

An application raises the NetworkAvailabilityChanged event every time that 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.

This event is raised on the application's main thread with the other user-interface events. This enables the event handler to access directly the application's UI. 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.

The NetworkAvailabilityChanged event provides the same functionality as this event but is available for all application types.

The code for the NetworkAvailabilityChanged event handler is stored in the ApplicationEvents.vb file, which is hidden by default.

To access the Code Editor window for application events

  1. Have a project selected in Solution Explorer. Click Properties on the Project menu.

  2. Click the Application tab.

  3. Click the View Application Events button to open the Code Editor.

    For more information, see Application Page, Project Designer (Visual Basic).

NoteNote

Many network hubs will provide a network connection even if the hub is disconnected from a larger network. Consequently, for wired connections, this event indicates change in the connection between the computer and a hub.

NoteNote

The NetworkAvailabilityChanged event is not raised by applications when they are run on Windows 95 and Windows 98, or when they are run by a non-administrator on Windows 2000. If your application might run on those operating systems, use the IsAvailable property to check for network availability.

Availability by Project Type

Project type

Available

Windows Forms Application

Yes

Class Library

No

Console Application

No

Windows Forms Control Library

No

Web Control Library

No

Windows Service

No

Web Site

No

This example calls the SetConnectionStatus method of the default Form1 class when the network availability changes.

You must enter the code in the Code Editor window for application events. To access this window, follow the instructions from this topic's Remarks section.

The project should have a form named Form1. It should have a method named SetConnectionStatus that takes a Boolean parameter.

Private Sub MyApplication_NetworkAvailabilityChanged( 
    ByVal sender As Object, 
    ByVal e As Microsoft.VisualBasic.Devices.NetworkAvailableEventArgs 
) Handles Me.NetworkAvailabilityChanged
    My.Forms.Form1.SetConnectionStatus(e.IsNetworkAvailable)
End Sub

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft