Ejemplo n.º 1
0
        // 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;
        }
Ejemplo n.º 2
0
        // 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;
        }
Ejemplo n.º 3
0
        // 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)));
            }
        }
Ejemplo n.º 4
0
        // 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)));
            }
        }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
 // Constructor to initialize the timer data
 public TimerEvent(int milliSeconds, TimerEventArgs e)
 {
     this.delayMilliSeconds = milliSeconds;
     this.eventName         = e.OwnerName;
     this.message           = e.Message;
 }
Ejemplo n.º 7
0
 // 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();
 }
Ejemplo n.º 8
0
 // 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();
 }