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.

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)

public delegate void NetworkAddressChangedEventHandler(
	Object sender,
	EventArgs e
)

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 null. 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
{
  static bool online = false; 

  public static void Demo(System.Windows.Controls.TextBlock outputBlock)
  {

      // Initialize the online variable and set a NetworkChange handler
      SetupNetworkChange();

      outputBlock.Text += "Network is: ";
      if (online)
          outputBlock.Text += "online";
      else     
          outputBlock.Text += "offline";

      // Now start the main work of the application        
  }

  // method that gets called when the network changes
  static void OnNetworkChange(object sender, EventArgs e)
  {
     if (NetworkInterface.GetIsNetworkAvailable())
     {
         if (!online)
          {
             online = true;
             // do what is needed to GoOnline();
          }
     }
     else {
         if (online)
         {
             online = false;
             // do what is needed to GoOffline();
         }
     }
  }

  private static void SetupNetworkChange()
  {
     // Get current network availalability and store the 
     // initial value of the online variable
     if (NetworkInterface.GetIsNetworkAvailable())
     {
         online = true;
         // do what is needed to GoOnline();
     }
     else
     {
         online = false;
         // do what is needed to GoOffline();
     }

      // Now add a network change event handler to indicate
      // network availability 
      NetworkChange.NetworkAddressChanged +=
          new NetworkAddressChangedEventHandler(OnNetworkChange);
  }
}


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft