Timer - temporay pause

G

Guest

I have a program that I need the program to temporarly stop and wait for a
response from a piece of equipment. After a set period I want the program to
continue. Like below

--execute lline before pause
--pause statement- pausefor set period
--execute line after pause

I tried using a timer but the timer messes up my sequence of execution. I
used a do loop that kept checking the current time versus the starting time.
This works but when the loop executes it hogs the CPU. It there a way I can
use a timer to pause, then execute the next line in the program instead of
excuting a function when the timer times out?

Thanks in advance,
 
N

Nicholas Paldino [.NET/C# MVP]

Dave,

Why not just put the thread to sleep? You can do this through the
static Sleep method on the Thread class.

However, a better design would be to use a event or something like that
and wait until the response comes in (the event would be set on another
thread when the response comes in).

Hope this helps.
 
R

rossum

Dave,

Why not just put the thread to sleep? You can do this through the
static Sleep method on the Thread class.

However, a better design would be to use a event or something like that
and wait until the response comes in (the event would be set on another
thread when the response comes in).

Hope this helps.

To avoid waiting for too long it might be better to have two events
the second being the expiry of a Thread.Sleep() on a different thread.
The main thread resumes whenever the first of the two events fires.

rossum


The ultimate truth is that there is no ultimate truth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top