瀏覽代碼

Do nothing in timer callback when device locator is disposed

cvium 4 年之前
父節點
當前提交
610a30d791
共有 1 個文件被更改,包括 6 次插入8 次删除
  1. 6 8
      RSSDP/SsdpDeviceLocator.cs

+ 6 - 8
RSSDP/SsdpDeviceLocator.cs

@@ -97,6 +97,11 @@ namespace Rssdp.Infrastructure
 
         private async void OnBroadcastTimerCallback(object state)
         {
+            if (IsDisposed)
+            {
+                return;
+            }
+
             StartListeningForNotifications();
             RemoveExpiredDevicesFromCache();
 
@@ -180,8 +185,6 @@ namespace Rssdp.Infrastructure
         /// <exception cref="ObjectDisposedException">Throw if the <see cref="DisposableManagedObjectBase.IsDisposed"/>  ty is true.</exception>
         public void StartListeningForNotifications()
         {
-            ThrowIfDisposed();
-
             _CommunicationsServer.RequestReceived -= CommsServer_RequestReceived;
             _CommunicationsServer.RequestReceived += CommsServer_RequestReceived;
             _CommunicationsServer.BeginListeningForBroadcasts();
@@ -353,7 +356,7 @@ namespace Rssdp.Infrastructure
             {
                 return;
             }
-            
+
             var location = GetFirstHeaderUriValue("Location", message);
             if (location != null)
             {
@@ -515,11 +518,6 @@ namespace Rssdp.Infrastructure
 
         private void RemoveExpiredDevicesFromCache()
         {
-            if (this.IsDisposed)
-            {
-                return;
-            }
-
             DiscoveredSsdpDevice[] expiredDevices = null;
             lock (_Devices)
             {