Thread.Sleep Shared Method

Makes the current thread wait until a specified number of milliseconds have passed.

Thread.Sleep( milliseconds)

Prerequisites

None

Parameters

milliseconds

The number of milliseconds that this thread should wait before continuing execution with the next statement. May contain a fractional component. A value of 0 means allow another thread to execute, but continue execution of the current thread immediately if no other thread is ready. A value < 0 means wait forever, and is equivalent to invoking the Suspend method for the current task.

Remarks

This shared method is normally associated with the thread class, not an object. If it is used with an object, the current thread always waits, regardless of the thread object contents.

The milliseconds parameter may contain a fractional component that permits waiting for less than 1 millisecond. Any fraction is rounded up to a multiple of 0.125 milliseconds, which is the minimum wait time on a Precise controller.

Because of interactions between user threads and higher priority system threads, sleep times can be subject to milliseconds of jitter. Software should not be used to generate short time-critical intervals. The Thread.Schedule method can be used to minimize interactions with other threads of equal priority.

If a sleeping thread is suspended and resumed, the wait period restarts from the time that the thread was resumed.

Examples

Thread.Sleep(5000)                ' The current thread waits for 5 seconds 

Dim thread1 As New Thread(“Test”) ' Create an object for a different thread
thread1.Sleep(1000) ' The current thread waits for 1 second

See Also

Thread Class | Thread.Schedule | thread_object.SendEvent | Thread.WaitEvent