} // end of method /// <summary> /// SendMessageToUsers /// Transmit to Registered Users & Callbacks /// Logs off any disconnected clients /// </summary> /// <param name="message">The message to send to all clients (ChatMessage)</param> private void SendMessageToUsers(ChatMessage message) { // Inform all of the clients of the new message List <string> callbackKeys = loggedInUsers?.Keys.ToList(); // Loops through each logged in user foreach (string key in callbackKeys) { try { IChatServiceCallback callback = loggedInUsers[key]; callback.SendClientMessage(message); Console.WriteLine($"Sending user {key} message {message}"); } // catches an issue with a user disconnect and loggs off that user catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace + "." + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name); // Remove the disconnected client Logoff(key); } } // end of foreach } // end of method