Getting change in system clock in C #

Is this a way to execute delegateor eventin C # when seconds, minutes, hours, ... change the system clock without using a timer that checks every millisecond if the property has changed and executes the event with a delay of a maximum of a millisecond.

Therefore, I want to avoid interrogation and fire events at a certain time.

+3
source share
3 answers

If your question is: "How to execute a delegate every second / minute / hour?"

For minute and hour intervals you can do something like my answer in this SO question:

, .

1- . , , , xx: xx: xx.000 xx: xx: xx.350.

+7

I solved this in the forms application by setting the interval (1000 - DateTime.Now.Millisecond)

        _timer1 = new System.Windows.Forms.Timer();
        _timer1.Interval = (1000 - DateTime.Now.Millisecond);
        _timer1.Enabled = true;
        _timer1.Tick += new EventHandler(updateDisplayedTime);

and in the event handler reset the interval to prevent drift.

        <handle event>
        _timer1.Interval = (1000 - DateTime.Now.Millisecond);
+3
source

Source: https://habr.com/ru/post/1717850/


All Articles