Re: DateTime Ticks/Milliseconds Question (possibly Thread.Sleep () related - ?)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



The resolution of the system clock isn't 1/1000 second, but rathter something like 1/62 second. There is an interrupt that increases an integer value 62 (?) times a second, this integer value is then converted to a time value when you use DateTime.Now.

Every time you see the time change, the interrupt has increased the integer value by one, and that translates to an increase in time of about 16 ms.

Mr Bounce wrote:
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

.



Relevant Pages

  • Re: Post processing of NTP data...
    ... Setting aside for a moment the issue of ntp itself and the roping in of the system clock, is the crux of the problem that the processing of interrupts is too unpredictable? ... When an event occurs and an interrupt is registered, the speed of the processor or more accurately, the speed in which it can be preempted seems to me to be the limiting factor. ... It occurs to me that even a stratum 1 server is at the mercy of interrupt processing when the reference clock registers a new signal of some kind. ...
    (comp.protocols.time.ntp)
  • Re: Get time in milliseconds
    ... The Interrupt 1A provide only HH MM SS. ... int 70h will be invoked every 976 ... That lets up update your time at roughly millisecond ... If you have a GPS unit, ...
    (comp.lang.asm.x86)
  • Re: Assistance with PPS on Windows
    ... "unruh" wrote in message ... I do not believe that you can service an interrupt, and read a system clock ... If you have specialised hardware on the PC (as someone ...
    (comp.protocols.time.ntp)
  • Re: Monitor RS232 comms with millisecond resolution
    ... Not sure about all forms of Windows and system clock ... To get 1ms resolution, all you need is a clock. ... I think, you could use com2: tx interrupt to increment a counter which could be used as a timer which is faster than 1/18,5 Hz. ...
    (comp.arch.embedded)
  • H8S timer configuration problem
    ... I am having a problem generating a period interrupt on an H8S2329. ... System clock is 22.1184MHz throughout. ... any difference what I set TGR1A to, the interrupt is as if it is set to its ...
    (comp.arch.embedded)