NetworkChange.NetworkAddressChanged Evento
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Si verifica quando cambia l'indirizzo IP di un'interfaccia di rete.
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;
[System.Runtime.Versioning.UnsupportedOSPlatform("illumos")]
[System.Runtime.Versioning.UnsupportedOSPlatform("solaris")]
[System.Runtime.Versioning.UnsupportedOSPlatform("haiku")]
public static event System.Net.NetworkInformation.NetworkAddressChangedEventHandler? NetworkAddressChanged;
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
[<System.Runtime.Versioning.UnsupportedOSPlatform("illumos")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("solaris")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("haiku")>]
member this.NetworkAddressChanged : System.Net.NetworkInformation.NetworkAddressChangedEventHandler
Public Shared Custom Event NetworkAddressChanged As NetworkAddressChangedEventHandler
Tipo evento
- Attributi
Esempio
L'esempio di codice seguente è in ascolto delle modifiche degli indirizzi e visualizza lo stato delle interfacce di rete quando si verifica un NetworkAddressChanged evento.
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
Commenti
La NetworkChange classe genera NetworkAddressChanged eventi quando cambia l'indirizzo di un'interfaccia di rete, detta anche scheda o scheda di rete.
Per fare in modo che un oggetto chiami un NetworkChange metodo di gestione degli eventi quando si verifica un NetworkAddressChanged evento, è necessario associare il metodo a un NetworkAddressChangedEventHandler delegato e aggiungere questo delegato a questo evento.