NetworkAddressChangedEventHandler Delegate
References one or more methods to be called when the address of a network interface changes.
Namespace: System.Net.NetworkInformation
Assembly: System.Net (in System.Net.dll)
'Declaration Public Delegate Sub NetworkAddressChangedEventHandler ( _ sender As Object, _ e As EventArgs _ )
Parameters
- sender
- Type: System.Object
The source of the event.
- e
- Type: System.EventArgs
An EventArgs object that contains data about the event.
This delegate handles NetworkAddressChanged events raised by the NetworkChange class. For detailed information on receiving notification for network interface address change events, see the NetworkChange class overview documentation
The sender parameter passed to this event handler is always Nothing. The EventArgs object in the e parameter passed to this event handler is always empty. These parameters are not needed, since an application receiving this event can call the GetIsNetworkAvailable static method to determine network availability.
The following example uses a NetworkAddressChangedEventHandler to handle NetworkAddressChanged events and detect when network availability changes.
Public class Example Dim Shared online As Boolean = False Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock) ' Initialize the online variable and set a NetworkChange handler SetupNetworkChange() outputBlock.Text &= "Network is: " If online Then outputBlock.Text &= "online" Else outputBlock.Text &= "offline" End If ' Now start the main work of the application End Sub ' Subroutine that gets called when the network changes Private Shared Sub OnNetworkChange (ByVal sender As object, _ ByVale AS EventArgs) If NetworkInterface.GetIsNetworkAvailable() Then If Not online Then online = True ' do what is needed to GoOnline() End If Else If online Then online = False ' do what is needed to GoOffline() End If End If End Sub Private Shared Sub SetupNetworkChange() ' Get current network availalable and store the ' initial value for online value If NetworkInterface.GetIsNetworkAvailable() Then online = true ' do what is needed to GoOnline() Else online = false ' do what is needed to GoOffline() End If ' Now add a network change event handler to indicate ' network availability AddHandler NetworkChange.NetworkAddressChanged , _ AddressOf OnNetworkChange End Sub End Class
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.