private static void AddressChangedCallback(object stateObject, bool signaled)
{
lock (s_callerArray)
{
// The listener was canceled, which would only happen if we aren't listening for more events.
s_isPending = false;
if (!s_isListening)
{
return;
}
s_isListening = false;
// Need to copy the array so the callback can call start and stop
var copy = new Dictionary<NetworkAddressChangedEventHandler, ExecutionContext>(s_callerArray);
try
{
//wait for the next address change
StartHelper(null, false, (StartIPOptions)stateObject);
}
catch (NetworkInformationException nie)
{
if (NetEventSource.IsEnabled) NetEventSource.Error(null, nie);
}
foreach (var handler in copy.Keys)
{
ExecutionContext context = copy[handler];
if (context == null)
{
handler(null, EventArgs.Empty);
}
else
{
ExecutionContext.Run(context, s_runHandlerCallback, handler);
}
}
}
}