Пример #1
0
        protected virtual void OnRaiseCustomEvent(TimerEventArgs 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<TimerEventArgs> handler = RaiseTimerEvent;

            // Event will be null if there are no subscribers 
            if (handler != null)
            {
                // Format the string to send inside the CustomEventArgs parameter
                e.Message += DateTime.Now.ToString();

                // Use the () operator to raise the event.
                handler(this, e);
            }
        }
 // Define what actions to take when the event is raised. 
 private void HandleTimerEvent(object sender, TimerEventArgs e)
 {
     Console.WriteLine(e.Message);
 }