By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,738 Members | 1,682 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,738 IT Pros & Developers. It's quick & easy.

Timer - temporay pause

P: n/a
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,

Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dave" <Da**@discussions.microsoft.com> wrote in message
news:57**********************************@microsof t.com...
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,

Nov 17 '05 #2

P: n/a
On Tue, 21 Jun 2005 12:47:55 -0400, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
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
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.