Skip to content

Commit

Permalink
detect network change on Mac Catalina (#89)
Browse files Browse the repository at this point in the history
* fix: detect network change on Mac Catatlina #87

Only do magic from @eshvatskyi on Windows.  Removing/Adding event handler causes
infinitive recursion on Catalina.

* fix: always check for windows
  • Loading branch information
richardschneider authored Nov 2, 2019
1 parent 81281a8 commit 20f4e40
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/MulticastService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -330,8 +331,16 @@ void FindNetworkInterfaces()
// (wifi off, but NIC is not disabled, wifi - on, NIC was not changed
// so no event). Rebinding fixes this.
//
NetworkChange.NetworkAddressChanged -= OnNetworkAddressChanged;
NetworkChange.NetworkAddressChanged += OnNetworkAddressChanged;
// Do magic only on Windows.
#if NET461
if (Environment.OSVersion.Platform.ToString().StartsWith("Win"))
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
#endif
{
NetworkChange.NetworkAddressChanged -= OnNetworkAddressChanged;
NetworkChange.NetworkAddressChanged += OnNetworkAddressChanged;
}
}
catch (Exception e)
{
Expand Down Expand Up @@ -673,7 +682,7 @@ public void OnDnsMessage(object sender, UdpReceiveResult result)
}
}

#region IDisposable Support
#region IDisposable Support

/// <inheritdoc />
protected virtual void Dispose(bool disposing)
Expand All @@ -690,6 +699,6 @@ public void Dispose()
Dispose(true);
}

#endregion
#endregion
}
}

0 comments on commit 20f4e40

Please # to comment.