Example #1
0
        // Wrap event invocations inside a protected virtual method
        // to allow derived classes to override the event invocation behavior
        protected virtual void RaiseOnRecieve(DataRecieveEventArgs e)
        {
            // Make a temporary copy of the event to avoid possibility of
            // a race condition if the last subscriber unsubscribes
            // immediately after the null check and before the event is raised.
            EventHandler<DataRecieveEventArgs> handler = OnRecieve;

            // Event will be null if there are no subscribers
            if (handler != null)
            {
                // Set the Time of the message
                e.Time = DateTime.Now;

                // Use the () operator to raise the event.
                handler(this, e);
            }
        }
Example #2
0
 private void onRecieve(object sender, DataRecieveEventArgs e)
 {
     if (this.txtConsole.InvokeRequired)
     {
         onRecieveCallback d = new onRecieveCallback(onRecieve);
         this.Invoke(d, new object[] { sender, e });
     }
     else
     {
         txtConsole.Text += e.Data;
         txtConsole.Text +=  " - " + e.Time.ToString()+ "\r\n";
         game.processMsg(e.Data);
         updateInterface();
     }
 }