コード例 #1
0
        // 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;
            }
        }
コード例 #2
0
 protected void onUpdate()
 {
     _secondsTimer -= Time.deltaTime;
     if (_secondsTimer < 0)
     {
         _secondsTimer = 1f;
         SecondChanged?.Invoke(0);
     }
 }
コード例 #3
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);
            }
        }
コード例 #4
0
        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);
                }
            }
        }
コード例 #5
0
 public void NotifySecondChanged(DateTime dateTime)
 {
     SecondChanged?.Invoke(this, dateTime);
 }