// Constructor to store object dataa and to subscribe event public TimerEventHandler(TimerEventArgs e, TimerEvent timerEvent) { this.eventHandlerName = e.OwnerName; this.message = e.Message; // Subscribe to the event using C# 2.0 syntax timerEvent.RaiseTimerEvent += HandleTimerEvent; }
// Raise the event in virtual method protected virtual void OnRaiseTimerEvent(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) { // Use the () operator to raise the event. handler(this, new TimerEventArgs(e.OwnerName, String.Format("{0} say '{1}' to event subscriber!", e.OwnerName, e.Message))); } }
// Raise the event in virtual method protected virtual void OnRaiseTimerEvent(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) { // Use the () operator to raise the event. handler(this, new TimerEventArgs(e.OwnerName, String.Format("{0} say '{1}' to event subscriber!", e.OwnerName, e.Message))); } }
private ulong repetitionCount; // Count timer runs #endregion Fields #region Constructors // Constructor to initialize the timer data public TimerEvent(int milliSeconds, TimerEventArgs e) { this.delayMilliSeconds = milliSeconds; this.eventName = e.OwnerName; this.message = e.Message; }
// Constructor to initialize the timer data public TimerEvent(int milliSeconds, TimerEventArgs e) { this.delayMilliSeconds = milliSeconds; this.eventName = e.OwnerName; this.message = e.Message; }
// Define what actions to take when the event is raised. void HandleTimerEvent(object sender, TimerEventArgs e) { Console.WriteLine(e.Message); Console.WriteLine("{0} replay '{1}'.", this.eventHandlerName, this.message); Console.WriteLine(); }