NetworkChange.NetworkAddressChanged NetworkChange.NetworkAddressChanged NetworkChange.NetworkAddressChanged NetworkChange.NetworkAddressChanged Event

Definition

Tritt ein, wenn sich die IP-Adresse einer Netzwerkschnittstelle ändert.Occurs when the IP address of a network interface changes.

public:
 static event System::Net::NetworkInformation::NetworkAddressChangedEventHandler ^ NetworkAddressChanged;
public static event System.Net.NetworkInformation.NetworkAddressChangedEventHandler NetworkAddressChanged;
member this.NetworkAddressChanged : System.Net.NetworkInformation.NetworkAddressChangedEventHandler 
Public Shared Custom Event NetworkAddressChanged As NetworkAddressChangedEventHandler 

Beispiele

Im folgenden Codebeispiel wird lauscht, für die Adresse ändert sich und zeigt der Status des Netzwerks, wenn Schnittstellen eine NetworkAddressChanged Ereignis auftritt.The following code example listens for address changes and displays the status of network interfaces when a NetworkAddressChanged event occurs.

#using <System.dll>

using namespace System;
using namespace System::Net;
using namespace System::Net::NetworkInformation;
void AddressChangedCallback( Object^ /*sender*/, EventArgs^ /*e*/ )
{
   array<NetworkInterface^>^adapters = NetworkInterface::GetAllNetworkInterfaces();
   System::Collections::IEnumerator^ myEnum = adapters->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      NetworkInterface^ n = safe_cast<NetworkInterface^>(myEnum->Current);
      Console::WriteLine( "   {0} is {1}", n->Name, n->OperationalStatus );
   }
}

int main()
{
   NetworkChange::NetworkAddressChanged += gcnew NetworkAddressChangedEventHandler( AddressChangedCallback );
   Console::WriteLine( "Listening for address changes. Press any key to exit." );
   Console::ReadLine();
}

using System;
using System.Net;
using System.Net.NetworkInformation;

namespace Examples.Net.AddressChanges
{
    public class NetworkingExample
    {
        public static void Main()
        {
            NetworkChange.NetworkAddressChanged += new 
            NetworkAddressChangedEventHandler(AddressChangedCallback);
            Console.WriteLine("Listening for address changes. Press any key to exit.");
            Console.ReadLine();
        }
        static void AddressChangedCallback(object sender, EventArgs e)
        {
            
            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
            foreach(NetworkInterface n in adapters)
            {
                Console.WriteLine("   {0} is {1}", n.Name, n.OperationalStatus);
            }
        }
    }
}
Imports System
Imports System.Net
Imports System.Net.NetworkInformation

Public Class NetworkingExample
    Public Shared Sub Main()
        AddHandler NetworkChange.NetworkAddressChanged, AddressOf AddressChangedCallback
        Console.WriteLine("Listening for address changes. Press any key to exit.")
        Console.ReadLine()
    End Sub 'Main
    Private Shared Sub AddressChangedCallback(ByVal sender As Object, ByVal e As EventArgs)

        Dim adapters As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
        Dim n As NetworkInterface
        For Each n In adapters
            Console.WriteLine("   {0} is {1}", n.Name, n.OperationalStatus)
        Next n
    End Sub
End Class

Hinweise

Die NetworkChange löst NetworkAddressChanged Ereignisse aus, wenn die Adresse einer Netzwerkschnittstelle, die so genannte eine Netzwerkkarte oder-Adapter ändert.The NetworkChange class raises NetworkAddressChanged events when the address of a network interface, also called a network card or adapter, changes.

Damit eine NetworkChange Objekt aufrufen eine Methode zur Verarbeitung von Ereignissen beim eine NetworkAddressChanged Ereignis auftritt, müssen Sie die Methode mit Zuordnen einer NetworkAddressChangedEventHandler delegieren, und fügen Sie diesen Delegaten auf dieses Ereignis.To have a NetworkChange object call an event-handling method when a NetworkAddressChanged event occurs, you must associate the method with a NetworkAddressChangedEventHandler delegate, and add this delegate to this event.

Die NetworkAddressChanged Ereignis wird unter Windows 2000 und höher unterstützt.The NetworkAddressChanged event is supported on Windows 2000 and later.

Gilt für: