T
Tam Bui
Guest
I have a simple .NET Core Console application with the following code in Program.cs:
using System;
using System.Net.NetworkInformation;
namespace ApplicationBridgeTestConsole
{
class Program
{
static void Main(string[] args)
{
NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;
NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
Console.WriteLine("Hit any key to exit.");
Console.ReadKey();
}
private static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
{
Console.WriteLine($"NetworkAvailability Changed: IsAvailable = {e.IsAvailable}");
}
private static void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
{
Console.WriteLine($"Network Address Changed");
}
}
}
When I target the console app to .NET Core 2.0, and I connect/disconnect an ethernet cable to my network, I get the following output:
This tells me that the NetworkAvailabilityChanged event either isn't implemented, or it's not working! Even though Microsoft docs indicate that it is supports: https://docs.microsoft.com/en-us/dotnet/api/system.net.networkinformation.networkchange.networkavailabilitychanged?view=netframework-4.7.2
When I target the console app to .NET Core 2.1, and I connect/disconnect an ethernet cable to my network, I get the following output:
This is even worse on Core 2.1 than on 2.0! As you can see, not only is NetworkAvailabilityChanged not working, but also NetworkAddressChanged only worked on ethernet disconnection, but does not work when I connect the ethernet cable back. I have tested this multiple times, and on three different devices, all with similar results. NetworkAvailabilityChanged event just does not work on .NET Core.
Can anyone else confirm? I thank you much and appreciate you taking time to read this post.
Continue reading...
using System;
using System.Net.NetworkInformation;
namespace ApplicationBridgeTestConsole
{
class Program
{
static void Main(string[] args)
{
NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;
NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
Console.WriteLine("Hit any key to exit.");
Console.ReadKey();
}
private static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
{
Console.WriteLine($"NetworkAvailability Changed: IsAvailable = {e.IsAvailable}");
}
private static void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
{
Console.WriteLine($"Network Address Changed");
}
}
}
When I target the console app to .NET Core 2.0, and I connect/disconnect an ethernet cable to my network, I get the following output:
This tells me that the NetworkAvailabilityChanged event either isn't implemented, or it's not working! Even though Microsoft docs indicate that it is supports: https://docs.microsoft.com/en-us/dotnet/api/system.net.networkinformation.networkchange.networkavailabilitychanged?view=netframework-4.7.2
When I target the console app to .NET Core 2.1, and I connect/disconnect an ethernet cable to my network, I get the following output:
This is even worse on Core 2.1 than on 2.0! As you can see, not only is NetworkAvailabilityChanged not working, but also NetworkAddressChanged only worked on ethernet disconnection, but does not work when I connect the ethernet cable back. I have tested this multiple times, and on three different devices, all with similar results. NetworkAvailabilityChanged event just does not work on .NET Core.
Can anyone else confirm? I thank you much and appreciate you taking time to read this post.
Continue reading...