Click to See Complete Forum and Search --> : VB and Delays
Mike Hurley
August 5th, 1999, 05:44 AM
Does any know of the best way to put a delay in a VB APP.
I'm using the Shell command to mount a network drive using the 'NET USE' statement. I have noticed that it can take from between 1 second to 20 seconds to successfully mount the drive. However, my VB App has continued to the next statements that rely on the mounted drive being there.
I need to delay my app for about 30 seconds before continuing. I can of course put a loop in there but this takes up CPU.
Any other way of doing this?
Lothar Haensler
August 5th, 1999, 05:59 AM
you can use the Sleep API (Sleep( 30 * 1000)).
But, be aware that this stops your app from responding to any events.
You could work around this by sleeping in portions of half a second or so.
Happy sleeping :-)
Mike Hurley
August 5th, 1999, 06:12 AM
Thanks for this.
I'm pretty new to VB, but where do I get the Sleep command from. Its not in Standard VB.
Dr_Michael
August 5th, 1999, 06:14 AM
There is a way to make CPU not to halt:
You put inside the loop or before the line that Lothar posted this command:
DoEvents
So the PC can respond to any event during the delay :-)
Michael Vlastos
Company MODUS SA
Development Department
Athens, Greece
Tel: +3-01-9414900
Lothar Haensler
August 5th, 1999, 06:15 AM
put the following declaration in your code
public Declare Sub Sleep Lib "kernel32" (byval dwMilliseconds as Long)
then call it like that.
call sleep(30000)
to sleep for 30 seconds.
August 5th, 1999, 12:06 PM
Another possibilty worth investigating is to use the Windows API version of Shell called ShellExecute.This returns a handle to the application instance which can then be used in conjuction with another API called WaitForSingleObject to wait for the exact time that the operation takes and then continue.MSDN should have articles relating to the use of both in VB.
http://msdn.microsoft.com
Gorditos
August 5th, 1999, 06:04 PM
What I would do ... other than using Create Process and Wait for single Object ... is to create a timer object that will check to see if the network drive is ready ... after the point in your code where you use the shell function ... enable your timer, then end the subroutine. Set your timer interval ... every 10 seconds or so ... then in the timer code you can check to see if the drive is ready ... If the drive is available ... you disable the timer ... and call the appropriate subroutine to continue with your app.
Gordito Supreme
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.