468,514 Members | 1,121 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,514 developers. It's quick & easy.

Any better way to wait 60 seconds

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
Mar 6 '08 #1
5 3304
"Tony WONG" <x3*@netvigator.comwrote in message
news:eK***************@TK2MSFTNGP02.phx.gbl...
>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)?
Mar 6 '08 #2
Tony WONG wrote:
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.
Mar 6 '08 #3
"Trammel" <Me@Server.comwrote in message
news:E7*********************@fe3.news.blueyonder.c o.uk...
"Tony WONG" <x3*@netvigator.comwrote in message
news:eK***************@TK2MSFTNGP02.phx.gbl...
>>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)?
*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
Mar 6 '08 #4
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

"Trammel" <Me@Server.com撰寫於郵件新聞:E7******************* **@fe3.news.blueyonder.co.uk...
"Tony WONG" <x3*@netvigator.comwrote in message
news:eK***************@TK2MSFTNGP02.phx.gbl...
>>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)?

Mar 6 '08 #5
Thanks a lot. Steve & Trammel
"Steve Gerrard" <my********@comcast.net撰寫於郵件新聞:0s********** ********************@comcast.com...
Tony WONG wrote:
>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.


Mar 6 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Snuyt | last post: by
4 posts views Thread by Pierpaolo | last post: by
34 posts views Thread by pamela fluente | last post: by
40 posts views Thread by =?Utf-8?B?Um9iZXJ0IEUuIEZsYWhlcnR5?= | last post: by
5 posts views Thread by Jeremy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.