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

Is there a better way to "Wait"?

P: n/a
I wanted to do this "inline" and not use a timer. Is there a better way?

Do
zipError = UnzipFile(datPath & zipFileName, datPath, False)
If zipError = "Success" Then Exit Do
UpdateStatus("File in use, waiting 5 minutes")
Wait(5)
Loop

Public Sub Wait(ByVal minutes As Integer)
Dim startTime As Integer = Minute(Now)
Dim curTime As Integer
Do
curTime = Minute(Now)
If curTime < startTime Then curTime += 60
If curTime = startTime + minutes Then Exit Sub
Application.DoEvents()
Loop
End Sub
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Yes , there is a better way.
System.Threading.Thread.Sleep(new TimeSpan(0, 5, 0))
~Steve

"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I wanted to do this "inline" and not use a timer. Is there a better way?

Do
zipError = UnzipFile(datPath & zipFileName, datPath, False)
If zipError = "Success" Then Exit Do
UpdateStatus("File in use, waiting 5 minutes")
Wait(5)
Loop

Public Sub Wait(ByVal minutes As Integer)
Dim startTime As Integer = Minute(Now)
Dim curTime As Integer
Do
curTime = Minute(Now)
If curTime < startTime Then curTime += 60
If curTime = startTime + minutes Then Exit Sub
Application.DoEvents()
Loop
End Sub

Nov 21 '05 #2

P: n/a
On Tue, 24 Aug 2004 23:31:13 -0500, Steven Campbell wrote:
Yes , there is a better way.
System.Threading.Thread.Sleep(new TimeSpan(0, 5, 0))
~Steve


Sure, if you want your application to be locked up for 5 minutes... :)

--
Tom Shelton [MVP]
Nov 21 '05 #3

P: n/a
On Tue, 24 Aug 2004 22:09:14 -0600, Terry Olsen wrote:
I wanted to do this "inline" and not use a timer. Is there a better way?

Do
zipError = UnzipFile(datPath & zipFileName, datPath, False)
If zipError = "Success" Then Exit Do
UpdateStatus("File in use, waiting 5 minutes")
Wait(5)
Loop

Public Sub Wait(ByVal minutes As Integer)
Dim startTime As Integer = Minute(Now)
Dim curTime As Integer
Do
curTime = Minute(Now)
If curTime < startTime Then curTime += 60
If curTime = startTime + minutes Then Exit Sub
Application.DoEvents()
Loop
End Sub


As has been mentioned, there is System.Threading.Sleep - but I wouldn't use
that for extended periods of time or someones going to give your
application the 3-finger salute... You might want to use a timer control
or a System.Threading.Timer to reschedule your method.

--
Tom Shelton [MVP]
Nov 21 '05 #4

P: n/a
Terry,

When it is 5 minutes I would not use that long time I would give the user
some information how long it is to go.

That can be done either by the treading sleep or with one of the timers what
I prefer (for this form handling I prefer the forms.form.timer because it is
so easy to use and this is very easy timer handling).

To use the time sleep (all types here and not tested so nothing more as
almost complete pseudo)
\\\
Dim frm as new SplashForm
For i as integer = 1 to 100
frm.label = i * 300 ('you may translate it yourself nice using the
timespan)
frm.show
thread.threading.sleep(1000)
Next
frm.close
////
With the forms.form.timer event it is even easier to do.
(mostly is forgotten to enable that and set the correct wait time)

I hope this helps?

Cor
Nov 21 '05 #5

P: n/a
One error I saw beside the types (typed) the wait time in this sample
should be 3000 what is 3 seconds what is the normal time a user does not
recognise as wait time.

Cor
Nov 21 '05 #6

P: n/a
* "Terry Olsen" <to******@hotmail.com> scripsit:
I wanted to do this "inline" and not use a timer. Is there a better way?


'System.Threading.Thread.Sleep'. If you are using a Windows Forms
application, this will block the app's main UI thread. To avoid that,
perform the waiting in a separate thread.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.