// // METHOD: displayMessage() // DESCRIPTION: Allows a thread to access the UI's MessageRecievedTextbox object and write to it // PARAMETERS: string recievedMessage // RETURNS: void // private void displayMessage(string recievedMessage) { //check if this thread needs to access UI elements safely if (this.InvokeRequired) { //write the messafe to the MessageRecievedTextbox this.Invoke(new Action <string>(displayMessage), new object[] { recievedMessage }); } else //if the thread is accesses UI elements safely already { //write the message to the MessageRecievedTextbox MessageRecievedTextbox.AppendText(recievedMessage + Environment.NewLine); } }
// // METHOD: displayUsername() // DESCRIPTION: Allows a thread to access the UI's MessageRecievedTextbox object and write to it // PARAMETERS: string username // RETURNS: void // private void displayUsername(string username) { //check if this thread needs to access UI elements safely if (this.InvokeRequired) { //write the username to the MessageRecievedTextbox this.Invoke(new Action <string>(displayMessage), new object[] { username + " Says :" }); } else //if the thread is accesses UI elements safely already { //write the username to the MessageRecievedTextbox MessageRecievedTextbox.AppendText(username + " Says : "); } }