public WebChat StartChat(WebClient owner, string roomName) { //Find out of the owner has already stated this chat WebChat chat = Chats.SingleOrDefault(c => c.Owner.Equals(owner) && c.RoomName.ToLowerInvariant().Equals(roomName.ToLowerInvariant())); //If there is already a chat with the same name if (null != chat) { //There is alredy a chat with the same name, return it return(chat); } else { //Ensure on one thread is adding a chat lock (m_Chats) { //Create a new chat chat = new WebChat(owner, roomName); //Add it to the Server m_Chats.Add(chat.RoomId, chat); } } //Return the chat return(chat); }
internal void RemoveChat(ref WebChat chat) { lock (m_Chats) { //Empty the chat chat.Empty(); //Remove the existing chat m_Chats.Remove(chat.RoomId); chat = null; } }