Any better way to wait 60 seconds

  • Thread starter Thread starter Tony WONG
  • Start date Start date
T

Tony WONG

i have a "for next" program to detect workstations ON/OFF status by ping.

i wish the program restart after 60 seconds after completion of for next
loop.

at present, i use "System.Threading.Thread.Sleep(60000)"

however i find the UI hang up during thread sleep.

i do not want to use timer cos the running time of the next loop varies,
depend on the how many workstations are ON.

any better way to let the program wait without affecting the response of UI?
Thanks a lot.

tony
 
Tony WONG said:
i have a "for next" program to detect workstations ON/OFF status by ping.

i wish the program restart after 60 seconds after completion of for next
loop.

at present, i use "System.Threading.Thread.Sleep(60000)"

however i find the UI hang up during thread sleep.

i do not want to use timer cos the running time of the next loop varies,
depend on the how many workstations are ON.

any better way to let the program wait without affecting the response of
UI? Thanks a lot.

tony

A timer still looks like your best option.
If you want to change the interval then you can always use
Timer1.Interval=6000 (or whatever the delay you need at the present time).

I dont understand your reasoning behind not using a timer. Could you
clarify, or respond letting us know if you didnt know timer intervals could
be modified while the program is running (at runtime)?
 
Tony said:
i have a "for next" program to detect workstations ON/OFF status by
ping.
i wish the program restart after 60 seconds after completion of for
next loop.

at present, i use "System.Threading.Thread.Sleep(60000)"

however i find the UI hang up during thread sleep.

i do not want to use timer cos the running time of the next loop
varies, depend on the how many workstations are ON.

any better way to let the program wait without affecting the response
of UI? Thanks a lot.

Record the time, then use a timer with a short interval, say 1 sec, and check
the current time on each tick. Start the next round when a minute has gone by.

Or, you could disable the timer when you start your procedure; then restart it
when you are finished, and set it to 60 seconds.


Or, you could do a small loop, with Sleep(100) followed by DoEvents.
 
Trammel said:
A timer still looks like your best option.
If you want to change the interval then you can always use
Timer1.Interval=6000 (or whatever the delay you need at the present time).

I dont understand your reasoning behind not using a timer. Could you
clarify, or respond letting us know if you didnt know timer intervals
could be modified while the program is running (at runtime)?

*rereads question*

If you want the check to START again at 60000 after the LAST one is
checked...

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
'do loop stuff
Timer1.Enabled = True
End Sub
 
if it uses Timer to start at 00:00, the interval is 60s

if the job takes more 90s, the 2nd job starts immediately after 1st job

therefore, there is no time gap between the jobs

the job sometimes takes 30s, sometimes takes 150s

i hope there is some spare time at which program can do somethings else.

if it is not possible, it is still ok to set interval to 200s.

Thanks a lot.

tony
 
Thanks a lot. Steve & Trammel


Steve Gerrard said:
Record the time, then use a timer with a short interval, say 1 sec, and
check the current time on each tick. Start the next round when a minute
has gone by.

Or, you could disable the timer when you start your procedure; then
restart it when you are finished, and set it to 60 seconds.


Or, you could do a small loop, with Sleep(100) followed by DoEvents.
 
Tony WONG said:
if it uses Timer to start at 00:00, the interval is 60s

if the job takes more 90s, the 2nd job starts immediately after 1st job

therefore, there is no time gap between the jobs

the job sometimes takes 30s, sometimes takes 150s

i hope there is some spare time at which program can do somethings else.

if it is not possible, it is still ok to set interval to 200s.

Thanks a lot.

tony

A) Try not to TopPost when replying to a newsgroup as its breaks the natural
reading-order of newsgroups

B) When entering the _Tick event of the timer, use Timer1.Enabled=False, do
your loops then use Timer1.Enabled=True

The timer will get turned off when it ticks... your loop will do its
stuff... the timer will get turned on at the end (after loop is finished)
and wait for 60s (or whatever it was set for) before ticking again.
 
Back
Top