473,382 Members | 1,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Is there a better way to "Wait"?

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
6 1294
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
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
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
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
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
* "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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Vivien Mallet | last post by:
Hello, I use popen2.Popen4 and I experienced problems with it. Let me show you with an example. The following script is called "lines" (it prints lines of 'X'): ---------------------...
1
by: Alex Li | last post by:
Dear js/xmlhttp experts, I spent hours but could not solve this problem and hope someone could give me a clue: a onclick event will invoke a function to do a few things: 1. make a hidden DIV...
1
by: metsymani | last post by:
In my web application, I have a search screen coded in ASP.Net. The Search process takes lot of time. So, I need to show a wait page informing the user that "Search is in progress. Please wait" along...
3
by: John Dalberg | last post by:
Hi I have a form that opens a new window for the results. Because the results might take a few seconds due to server processing, I would like to display a message "please wait" in the new...
1
by: Huey | last post by:
Hi All, I encountered a funny thing, and my code schetch as below: #define READ 0 #define WRITE 1 int byteRead, status, pd; char buff;
3
by: Aaron Queenan | last post by:
I have a form which performs some asynchronous code. I want to display a wait cursor when it starts, and hide the wait cursor when it has completed. This part works fairly well, using: ...
1
by: VMI | last post by:
How can I add a small "Please wait..." form to a child form so that when I minimize the child form, the "Please Wait..." form will also disappear? This form will be displayed when the child form is...
5
by: Jeremy | last post by:
Hi all, I have database actions that will potentially take several seconds to complete. My normal page uses AJAX so keeping the user informed of what is happening is not a problem. ...
1
by: =?Utf-8?B?Sm9obiBXYWxrZXI=?= | last post by:
Hi, I have a webpage designed with asp.net 2.0. Is there a way to display a "please wait" message to the screen horizontally centered and veritcally 20px from the VISIBLE top of the page,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.