Saturday, September 29, 2007

Sleep in VB.NET and C#

The sleep is sometimes hard to find in .NET. Here is an example for VB.NET and C#:


Imports System.Threading

Dim waitTime as Integer = 300



using System.Threading;
int waitTime = 300;


The Sleep method can be used with both an integer and a TimeSpan parameter. An integer value can be used to specify the wait time in milliseconds, or the wait time can be specified as a TimeSpan like this:


Dim waitTime As New TimeSpan(0, 0, 0, 0, 300)

or in C#:

TimeSpan waitTime = new TimeSpan(0, 0, 0, 0, 300);

There is also a pretty good example at the following web site:

1 comment:

Anonymous said...

You don't need CurrentThread. System.Threading.Thread.Sleep should suffice.