M
Mr Bounce
Hi,
Slightly dim question, possibly. I dunno. When i run the following c#:
for (int i = 0; i < 100; i++)
{
System.Diagnostics.Debug.WriteLine
(DateTime.Now.Millisecond.ToString ());
System.Threading.Thread.Sleep (1);
}
I would expect the output to increment by at least 1 every line (since
I am asking my thread to sleep for 1 millisecond).
The output generated, however, looks like this:
627
409
409
409
424
424
440
440
440
456
456
456
456
(etc)
surely this is impossible?
I also noticed a similar thing when using Ticks instead of Milliseconds
Is there something im missing? I thought maybe it was something i hadnt
encountered before to do with thread scheduling (ie: none others to be
scheduled, so its not sleeping), but if i change the interval to 100ms
there is a visible (and seemigly regular) pause, and the output number
increments by slightly more than 100 each time round.
If anyone can shed some light on this i would be grateful - I'm now
wondering if its something to do with the clock speed of my PC...?
Thanks,
Chris
Slightly dim question, possibly. I dunno. When i run the following c#:
for (int i = 0; i < 100; i++)
{
System.Diagnostics.Debug.WriteLine
(DateTime.Now.Millisecond.ToString ());
System.Threading.Thread.Sleep (1);
}
I would expect the output to increment by at least 1 every line (since
I am asking my thread to sleep for 1 millisecond).
The output generated, however, looks like this:
627
409
409
409
424
424
440
440
440
456
456
456
456
(etc)
surely this is impossible?
I also noticed a similar thing when using Ticks instead of Milliseconds
Is there something im missing? I thought maybe it was something i hadnt
encountered before to do with thread scheduling (ie: none others to be
scheduled, so its not sleeping), but if i change the interval to 100ms
there is a visible (and seemigly regular) pause, and the output number
increments by slightly more than 100 each time round.
If anyone can shed some light on this i would be grateful - I'm now
wondering if its something to do with the clock speed of my PC...?
Thanks,
Chris