// set the clock running // it will raise an event for each new second public void Run() { for (; ;) { // sleep 10 milliseconds Thread.Sleep(100); // get the current time System.DateTime dt = System.DateTime.Now; // if the second has changed // notify the subscribers if (dt.Second != second) { // create the TimeInfoEventArgs object // to pass to the subscriber TimeInfoEventArgs timeInformation = new TimeInfoEventArgs(dt.Hour, dt.Minute, dt.Second); // if anyone has subscribed, notify them SecondChanged?.Invoke(this, timeInformation); } // update the state this.second = dt.Second; this.minute = dt.Minute; this.hour = dt.Hour; } }
protected void onUpdate() { _secondsTimer -= Time.deltaTime; if (_secondsTimer < 0) { _secondsTimer = 1f; SecondChanged?.Invoke(0); } }
public void Run() { for (;;) { Thread.Sleep(1000); DateTime now = DateTime.Now; TimeInfoEventArgs timeInfoEventArgs = new TimeInfoEventArgs(now.Hour, now.Minute, now.Second); Console.WriteLine($"{now.Hour}:{now.Minute}:{now.Second}"); SecondChanged?.Invoke(this, timeInfoEventArgs); } }
public void Run() { while (true) { Thread.Sleep(100); var now = DateTime.Now; if (now.Second != _second) { var timeInfoArgs = new TimeInfoEventArgs(now.Hour, now.Minute, now.Second); SecondChanged?.Invoke(this, timeInfoArgs); } } }
public void NotifySecondChanged(DateTime dateTime) { SecondChanged?.Invoke(this, dateTime); }