From 2aeacadefd89a4b6dcae67dfaf99d560603da9ac Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Wed, 7 Mar 2018 22:59:06 +1300 Subject: [PATCH] fix: more thread safety --- src/MulticastService.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/MulticastService.cs b/src/MulticastService.cs index 7d0f72e..d6872b8 100644 --- a/src/MulticastService.cs +++ b/src/MulticastService.cs @@ -198,10 +198,15 @@ void FindNetworkInterfaces(object state) // Tell others. if (nics.Length > 0) { - NetworkInterfaceDiscovered?.Invoke(this, new NetworkInterfaceEventArgs + lock (socketLock) { - NetworkInterfaces = nics - }); + if (socket == null || nicTimer == null) + return; + NetworkInterfaceDiscovered?.Invoke(this, new NetworkInterfaceEventArgs + { + NetworkInterfaces = nics + }); + } } }