WindowsDefender_WebApp.ChatHub.OnDisconnected C# (CSharp) Method

OnDisconnected() public method

User has disconnected.
public OnDisconnected ( bool stopCalled ) : System.Threading.Tasks.Task
stopCalled bool
return System.Threading.Tasks.Task
        public override Task OnDisconnected(bool stopCalled)
        {
            User user = null;
            Match match = null;

            try
            {
                // Get user
                _users.TryGetValue(Context.ConnectionId, out user);

                // Make sure user exists
                if (user == null)
                    throw new ArgumentNullException("user", "User does not exist in _users collection.");

                // Make sure user is part of a match
                if (user.MatchId == null)
                    throw new ArgumentNullException("user.MatchId", "User does not have a match id.");

                // Get match
                _matches.TryGetValue(user.MatchId, out match);
                if (match == null)
                    throw new ArgumentNullException("user.MatchId", "Match does not exist in _matches collection.");

                // Notify users
                SendToMatchExcept(user.MatchId, "<b>" + msg_icon + user.Name + " has left the game.</b>");

                // Remove user from match
                match.RemoveUser(user);

                // Update match's user list
                UpdateMatchUserLists(match);

                // Update match ready count
                UpdateReadyCount(match);

                // If match is now empty, close the match entirely
                if (match.Users.Count == 0)
                {
                    Match dummy = null;
                    _matches.TryRemove(match.Id, out dummy);
                }
            }
            catch (ArgumentNullException e) {
                Debug.WriteLine(e.ParamName + ": " + e.Message);
            }

            // Remove user
            User userdummy = null;
            if (user != null)
                _users.TryRemove(user.ConnectionId, out userdummy);

            return base.OnDisconnected(stopCalled);
        }