i’m not sure how the Windows kernel handles Thread timing …
i’m speaking about DST and any other event that affects the time of day on Windows boxes.
for example, Thread .Sleep will block a thread from zero to infinite milliseconds.
if the kernel uses the same “clock” as that used for time of day, then when
(a) someone manually changes the time of day, or
(b) some synchronization to a time server changes the time of day, or
(c) Daylight Saving Time begins or ends and the system has been configured to respond to these two DST events,
et cetera,
are sleeping threads in any way affected? i.e., does the kernel handle such events in such a way that the programmer need do nothing?
N.B.: for non-critical applications, this is likely a who cares? situation.
For critical applications, knowing the answer to this question is important because of the possibility that one must program for such exception conditions.
thank you
edit: i thought of a simple test which i’ve run in LINQPad 4.
the test involved putting the thread to sleep, starting a manual timer at approximately the same time as the thread was put to sleep, and then (a) moving the time ahead one hour, then for the second test, moving the time back two hours … in both tests, the period of sleep was not affected.
Bottom line: with Thread.Sleep, there is no need to worry about events that affect the time of day.
here’s the trivial c# code:
Int32 secondsToSleep;
String seconds;
Boolean inputOkay;
Console.WriteLine("How many seconds?");
seconds = Console.ReadLine();
inputOkay = Int32.TryParse(seconds, out secondsToSleep);
if (inputOkay)
{
Console.WriteLine("sleeping for {0} second(s)", secondsToSleep);
Thread.Sleep(secondsToSleep * 1000);
Console.WriteLine("i am awake!");
}
else Console.WriteLine("invalid input: [{0}]", seconds);
No,
Thread.Sleepis not affected. The kernel furthermore keeps time in UTC exclusively. Time zones and DST are just layered above that.