Ejemplo n.º 1
0
 public override void OnTimeChanged(object theClock, TimeEventArgs e)
 {
     Console.WriteLine("Logging event at {0}:{1}:{2}",
                       e.Hour.ToString(),
                       e.Minute.ToString(),
                       e.Second.ToString());
 }
Ejemplo n.º 2
0
        public void RunClock(int times)
        {
            for (int i = 0; i < times; ++i)
            {
                Thread.Sleep(100);
                DateTime currentTime = DateTime.Now;
                if (currentTime.Second != this.second)
                {
                    TimeEventArgs timeEventArgs = new TimeEventArgs()
                    {
                        Hour   = this.hour,
                        Minute = this.minute,
                        Second = this.second
                    };

                    // 5- invoke all the event handlers that subscribed to the event
                    TimeChanged?.Invoke(this, timeEventArgs);

                    this.hour   = currentTime.Hour;
                    this.minute = currentTime.Minute;
                    this.second = currentTime.Second;
                }
            }
        }
Ejemplo n.º 3
0
 // 3 - Define the event handler abstract function to be implemented in all derived classes:
 //      The Event Handler: public void On<Event>(object source, EventArg e):
 public abstract void OnTimeChanged(object theClock, TimeEventArgs e);