Which timers are dependent on system time?

后端 未结 2 1532
我寻月下人不归
我寻月下人不归 2021-01-04 05:19

I haven\'t tested this yet. I am hoping someone already knows the answer, so I don\'t have to write a test application, otherwise I will. :)

Usually when I want to c

2条回答
  •  死守一世寂寞
    2021-01-04 06:03

    I'll just quote Jim Mischel comments, as it's the most relevant answer to my question.

    None of the timers depend on the system time. That is, the user changing the clock will not affect System.Windows.Forms.Timer, System.Timers.Timer, or System.Threading.Timer. Nor will it affect Stopwatch or Environment.TickCount. Also, there's no "overhead" to using Stopwatch. It's not like the value is continually updated. It's lazily evaluated (i.e. Ticks is updated when it's referenced).

    Documentation for Stopwatch says: "TheStopwatch measures elapsed time by counting timer ticks in the underlying timer mechanism. If the installed hardware and operating system support a high-resolution performance counter, then the Stopwatch class uses that counter to measure elapsed time." If you look up info on the high-resolution performance counter, you'll see that it doesn't depend on the system time

    Timers are similar. System.Threading.Timer is based on Windows Timer Queue Timers. See that documentation. System.Timers.Timer is just a wrapper around System.Threading.Timer. System.Windows.Forms.Timer is a wrapper around the Windows SetTimer and KillTimer functions. Documentation for those indicates that they are not dependent on the system time.

提交回复
热议问题