This documentation is archived and is not being maintained.

Thread.Sleep Method

Blocks the current thread for the specified number of milliseconds.

Overload List

Suspends the current thread for a specified time.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub Sleep(Integer)
[C#] public static void Sleep(int);
[C++] public: static void Sleep(int);
[JScript] public static function Sleep(int);

Blocks the current thread for a specified time.

[Visual Basic] Overloads Public Shared Sub Sleep(TimeSpan)
[C#] public static void Sleep(TimeSpan);
[C++] public: static void Sleep(TimeSpan);
[JScript] public static function Sleep(TimeSpan);


[Visual Basic, C#, C++] The following code example demonstrates how to use a TimeSpan value with the Sleep method.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Sleep. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Imports System
Imports System.Threading

Public Class Test

    Shared waitTime As New TimeSpan(0, 0, 1)

    Shared Sub Main() 
        Dim newThread As New Thread(AddressOf Work)

        If newThread.Join( _
            TimeSpan.op_Addition(waitTime, waitTime)) Then

            Console.WriteLine("New thread terminated.")
            Console.WriteLine("Join timed out.")
        End If
    End Sub

    Shared Sub Work()
    End Sub

End Class

using System;
using System.Threading;

class Test
    static TimeSpan waitTime = new TimeSpan(0, 0, 1);

    public static void Main() 
        Thread newThread = 
            new Thread(new ThreadStart(Work));

        if(newThread.Join(waitTime + waitTime))
            Console.WriteLine("New thread terminated.");
            Console.WriteLine("Join timed out.");

    static void Work()

#using <mscorlib.dll>
using namespace System;
using namespace System::Threading;

static TimeSpan waitTime = TimeSpan(0, 0, 1);

__gc class Test
    static void Work()

void main() 
    Thread* newThread = new Thread(new ThreadStart(0, Test::Work));

    if(newThread->Join(waitTime + waitTime))
        Console::WriteLine(S"New thread terminated.");
        Console::WriteLine(S"Join timed out.");

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Thread Class | Thread Members | System.Threading Namespace