Inheritance: System.EventArgs
Example #1
0
 public static void OnStatusChanged(StatusChangedEventArgs e)
 {
     StatusChangedEventHandler statusHandler = StatusChanged;
     if (statusHandler != null)
     {
         //Invoke the delegate
         statusHandler(null, e);
     }
 }
Example #2
0
 public void mainServer_StatusChanged(object sender, StatusChangedEventArgs e)
 {
     // Call the method that updates the form
     this.Invoke(new UpdateStatusCallback(this.UpdateStatus), new object[] { e.EventMessage });
 }
Example #3
0
        //send message to user
        public static void SendMessage(string From, string Message)
        {
            StreamWriter swSenderSender;

            //First of all, show in our application who says what
            e = new StatusChangedEventArgs(From + " says: " + Message);
            OnStatusChanged(e);

            //Create an array of TCP clients, the size of the number of users we have
            TcpClient[] tcpClients = new TcpClient[ChatServer.htUsers.Count];
            //Copy the TcpClient objects into the array
            ChatServer.htUsers.Values.CopyTo(tcpClients, 0);
            //Loop through the list of TCP clients
            for (int i = 0; i < tcpClients.Length; i++)
            {
                //try sending a message to each
                try
                {
                    //if the message is blank or the connection is null, break out
                    if (Message.Trim() == "" || tcpClients[i] == null)
                        continue;

                    //Send the message to the current user in the loop
                    swSenderSender = new StreamWriter(tcpClients[i].GetStream());
                    swSenderSender.WriteLine(From + " says: " + Message);
                    swSenderSender.Flush();
                    swSenderSender = null;
                }
                catch // If there was a problem, the user is not there anymore, remove them
                {
                    RemoveUser(tcpClients[i]);
                }
            }
        }