vb.net, Threads & Sleep Command???

  • Thread starter Thread starter cgchris99
  • Start date Start date
C

cgchris99

Guest
I have a app that I am writing. I launches a couple threads that run
constantly. I have a timer in the thread to indicate how fast it is
executing a loop. I need this loop to be FAST. It must be 5ms or less. If
I put "thread.currentthread.priority.sleep(1)", the loop time is about 15ms.
This is on a 2Ghz PC with 1024MB Ram. If I completely remove the sleep, it
executes the loop in 0.013 ms. Yes, that's milliseconds.

Ideally, I would like a happy medium of about 3-5ms scan time would be
great. But the sleep command does not allow anything but an integer,
sleep(0.5) produces the same as no sleep command. The only reason I ask is
that I have other threads running and would like to give up some processing
to the others during the "sleep" time. If I put application.doevents
instead of sleep, the scan time fluctuates a lot. From 0.013 - 110ms.

Thanks for any advice
 
Set the threads priority to BelowNormal or Lowest. You shouldn't be using DoEvents in a loop in a thread you've created. Perhaps we could help more if you explained what you're doing with these loops.
 
One of the threads is scanning a memory address that is connected to a digital I/O board. I need to be able to see this input come on and go off.

It triggers at approx every 200ms. So it must be fast. What I have found is even if I get the thread running really fast. Like a complete scan in 0.015 ms the O/S takes over at random to do maintenance and the scan time jumps to about 110ms.

This is not acceptable. With a pause of 110ms I will completely miss the Digial I/O board trigger.

Thanks for any further advice
 
Back
Top