Timeout not timer?

ironfistchamp

Active member
Joined
Dec 9, 2005
Messages
29
Programming Experience
Beginner
I want to have a peice of code so that when a button is pressed it will wait a defined period of time before executing the rest of the code.

I don't want an actual timer just something that waits, oh I dont know, 5 seconds and then executes the code.

Any ideas folks?

Thanks

Ironfistchamp
 
kulrom said:
VB.NET:
Thread.Sleep(5000)

HTH
Regards ;)

I found this code on a search of the fourm, this is some that i need to be able to do in my little program, but when i add in your thread.sleep(5000) is says its not delclaried.

What do i need to delclaried as?

The code that i'm using is, where do i add in the line of code thread.sleep(5000). what i need it to do is, if it hasn't found the folder with 5 sec more on to the next if statement.

are you able to help me please..

If MK.FolderExists("\\manage-stn1\C$\winnt") Then
CheckBox1.CheckState = CheckState.Checked
End If
If MK.FolderExists("\\manage-stn2\C$\winnt") Then
CheckBox2.CheckState = CheckState.Checked
End If
If MK.FolderExists("\\manage-stn3\C$\winnt") Then
CheckBox2.CheckState = CheckState.Checked
End If
If MK.FolderExists("\\manage-stn4\C$\winnt") Then
CheckBox2.CheckState = CheckState.Checked
End If

Many THanks

Liam
 
taz-uk,

You must Import System.Threading.Thread before you can use the Sleep(5000) command.

But I think that in your case it might be better to use a Timer because sleep(5000) really "stops" the program for 5 seconds.
So when your application is "sleeping", you can't search the specified folder.
 
Last edited by a moderator:
Don't bother importing the namespace if you're just using it once. Simply qualify the class name instead:
VB.NET:
Threading.Thread.Sleep(5000)
You don't need to include the System part as every project already has the System namespace imported by default.
 
IronFistChamp... I use a Sleep() all the time in VB6. You can use the .net built in Sleep() method like stated above. I used it in VS2003 today.

I added a reference to the system.threading.thread namespace and then added an Imports statement like state before. Not "Import".

I'm interested if you use the full qualified name like...

VB.NET:
System.Threading.Thread.Sleep(5000)

If you still have to have the reference or not. [???]

Normally I would use a loop to do something (maybe processing) and sleep for a few minutes and loop back up and do it again.

Also, you might consider using the FileSystemWatcher class to monitor folders for specific type of files and then process them. I have not used this but it has great potential!!! :)

Dot Net Rocks - do google search for Dot Net Rocks and listen to the audio.
 
Back
Top