WindowsDefender_WebApp.Match.AddUser C# (CSharp) Method

AddUser() public method

Adds a user to the match. Uses a monitor lock to ensure multiple users are not writing to the list at the same time.
public AddUser ( User user ) : bool
user User The user to be added.
return bool
        public bool AddUser(User user)
        {
            lock (_usersLock)
            {
                if (Users.Count >= 4)
                    return false;

                Users.Add(user);
                return true;
            }
        }

Usage Example

Example #1
0
        /// <summary>
        /// Adds a user to his/her Match.
        /// If it doesn't exist yet then it will be created.
        /// </summary>
        /// <param name="user">The user (that was just created), to be added to the match.</param>
        private void AddToMatch(User user)
        {
            Match match;

            // Try and find match
            if (_matches.TryGetValue(user.MatchId, out match))
            {
                match.AddUser(user);
                if (DEBUG)
                    Console.WriteLine("DEBUG: Added " + user.Username + " to match");
            }
            // Match not found, create it
            else
            {
                match = new Match()
                {
                    ID = user.MatchId
                };
                match.AddUser(user);
                _matches.TryAdd(user.MatchId, match);
                if (DEBUG)
                    Console.WriteLine("DEBUG: Created new match and added " + user.Username + " to it.");
            }
        }