I need to delay program execution for a few seconds...
i.e
' Do stuff here
' delay for 5 seconds
' continue here
How can I do this?
Printable View
I need to delay program execution for a few seconds...
i.e
' Do stuff here
' delay for 5 seconds
' continue here
How can I do this?
VB Code:
System.Threading.Thread.Sleep(666)
Thanks, you're probly wondering why I would want to do this. Maybe you have a better idea. How can I run a loop until a service has been installed?
i.e
Dim sc as New ServiceController("MyService")
do until sc.exists()\
loop
But I can't find anything similar in the real world...
Look into the ServiceControlller's WaitForStatus functionality.
Problem is an exception is thrown when I call the serviceController object.
I wrote a function that returns true if no exception is thrown and false if an exception is thrown to check if the service is installed, but was wondering if there's a better way to do this...
Can you give us some source code of what you are trying to do?
Well,
All I'm doing is installing some third party services, and then trying to start them once they are installed.
The problem has been though that the app tries to start the service before its been installed. So If I create a service object i.e
Dim sc as New ServiceController("MyService")
And I try to reference the object, an exception is thrown.
What I ultimately want to do is check if the service is installed without throwing an exception.
But what I have done, which works is run a function that throws false if an exception occurs when it checks the service.
Any better way to do this?
Well, you could put a loop in there with some sleeps....
...try to create the ServiceController, catch any exceptions, if it excepted, sleep ten seconds and try again until you get success or a maximum amount of interations have occurred...