コード例 #1
0
        public override Task OnDisconnectedAsync(Exception exception)
        {
            _connections.TryRemove(Context.ConnectionId, out _);

            // Stop the Boinc background update loop if nobody is on the site.
            //
            // 'Count' operation in the ConcurrentDictionary cause it to acquire all the locks at once.
            // Alternative method, is the lock-free enumerator: concurrentDictionary.Skip(0).Count(), because it uses LINQ
            if (_connections.Skip(0).Count() == 0)
            {
                // Manager stops after 30 seconds
                _manager.Stop(30000).ContinueWith(task => Console.WriteLine("Error: BoincInfoHub.OnDisconnectedAsync: " + task.Exception), TaskContinuationOptions.OnlyOnFaulted);
            }

            return(base.OnDisconnectedAsync(exception));
        }