Aracılığıyla paylaş


NetworkChange.NetworkAddressChanged Olay

Tanım

Ağ arabiriminin IP adresi değiştiğinde gerçekleşir.

public:
 static event System::Net::NetworkInformation::NetworkAddressChangedEventHandler ^ NetworkAddressChanged;
public static event System.Net.NetworkInformation.NetworkAddressChangedEventHandler NetworkAddressChanged;
public static event System.Net.NetworkInformation.NetworkAddressChangedEventHandler? NetworkAddressChanged;
[System.Runtime.Versioning.UnsupportedOSPlatform("illumos")]
[System.Runtime.Versioning.UnsupportedOSPlatform("solaris")]
public static event System.Net.NetworkInformation.NetworkAddressChangedEventHandler? NetworkAddressChanged;
member this.NetworkAddressChanged : System.Net.NetworkInformation.NetworkAddressChangedEventHandler 
[<System.Runtime.Versioning.UnsupportedOSPlatform("illumos")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("solaris")>]
member this.NetworkAddressChanged : System.Net.NetworkInformation.NetworkAddressChangedEventHandler 
Public Shared Custom Event NetworkAddressChanged As NetworkAddressChangedEventHandler 

Olay Türü

Öznitelikler

Örnekler

Aşağıdaki kod örneği adres değişikliklerini dinler ve bir NetworkAddressChanged olay gerçekleştiğinde ağ arabirimlerinin durumunu görüntüler.

#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.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
    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

Açıklamalar

sınıfı NetworkChange , ağ kartı veya bağdaştırıcı olarak da adlandırılan bir ağ arabiriminin adresi değiştiğinde olayları tetikler NetworkAddressChanged .

Bir olay oluştuğunda NetworkAddressChanged bir NetworkChange nesnenin olay işleme yöntemini çağırmasını sağlamak için yöntemini bir NetworkAddressChangedEventHandler temsilciyle ilişkilendirmeniz ve bu temsilciyi bu olaya eklemeniz gerekir.

Şunlara uygulanır