diff --git a/src/Microsoft.AspNet.SignalR.Core/Messaging/Subscription.cs b/src/Microsoft.AspNet.SignalR.Core/Messaging/Subscription.cs index 825a13d1c..5aaeecc5a 100644 --- a/src/Microsoft.AspNet.SignalR.Core/Messaging/Subscription.cs +++ b/src/Microsoft.AspNet.SignalR.Core/Messaging/Subscription.cs @@ -277,7 +277,7 @@ protected virtual void Dispose(bool disposing) // if the client is very slow then this invoke call might not end quickly and this will make the CPU // hot waiting for the task to return. - var spinWait = new SpinWait(); + int disposeRetryCount = 0; while (true) { @@ -287,7 +287,7 @@ protected virtual void Dispose(bool disposing) SubscriptionState.Idle); // If we're not working then stop - if (state != SubscriptionState.InvokingCallback) + if (state != SubscriptionState.InvokingCallback || disposeRetryCount ++ > 10) { if (state != SubscriptionState.Disposed) { @@ -305,7 +305,7 @@ protected virtual void Dispose(bool disposing) break; } - spinWait.SpinOnce(); + Thread.Sleep(500); } } }