P
Pawan Singh
Hi,
I need a way for my thread to wake up at a specified time in .Net. I know
that windows is not a real time operating system, so I have to live with
much less precise timing. But what I am finding is that .Net thread.sleep is
inaccurate by 600 milliseconds some times. Most of the time, it is within 25
milliseconds which I am assuming is the Windows kernel scheduler quantum on
my XP machine. Since the problem happens with "Thread.Sleep" or
"Socket.Select" or any WaitOne method of events, I am assuming that is
either underlying Windows O/S issue or .Net framework issue. I have never
seen Win32 code miss the timing by such huge margin even when the CPU is
100% in use by some other process. But it happens all the time if CPU is
buys in .Net framework. So I am assuming that whatever layer which abstracts
Win32 threads and sleeps has some problems with it. Anyone has any
explanations?
Thanks
Pawan
Here is the piece of code for elucidation:
Dim start as Date = Now
thread.sleep(200) ' sleep for 200 milliseconds (you can put " sock.Select or
sock.Poll or WaitOne on some event here with valid timespans and result is
same)
Dim end as Date = Now
Dim diff as Timespan = end.Subtract(start)
' diff here is for the most part within 25 milliseconds. But sometimes, it
is off by 600 milliseconds or more even if the current thread's priority is
set to "highest".
' I can live with 25-50 milliseconds (even 100) but not 600 milliseconds.
That just seems incorrect on modern O/Ss with 3 Gigahertz CPUs)
I need a way for my thread to wake up at a specified time in .Net. I know
that windows is not a real time operating system, so I have to live with
much less precise timing. But what I am finding is that .Net thread.sleep is
inaccurate by 600 milliseconds some times. Most of the time, it is within 25
milliseconds which I am assuming is the Windows kernel scheduler quantum on
my XP machine. Since the problem happens with "Thread.Sleep" or
"Socket.Select" or any WaitOne method of events, I am assuming that is
either underlying Windows O/S issue or .Net framework issue. I have never
seen Win32 code miss the timing by such huge margin even when the CPU is
100% in use by some other process. But it happens all the time if CPU is
buys in .Net framework. So I am assuming that whatever layer which abstracts
Win32 threads and sleeps has some problems with it. Anyone has any
explanations?
Thanks
Pawan
Here is the piece of code for elucidation:
Dim start as Date = Now
thread.sleep(200) ' sleep for 200 milliseconds (you can put " sock.Select or
sock.Poll or WaitOne on some event here with valid timespans and result is
same)
Dim end as Date = Now
Dim diff as Timespan = end.Subtract(start)
' diff here is for the most part within 25 milliseconds. But sometimes, it
is off by 600 milliseconds or more even if the current thread's priority is
set to "highest".
' I can live with 25-50 milliseconds (even 100) but not 600 milliseconds.
That just seems incorrect on modern O/Ss with 3 Gigahertz CPUs)