C#idiomatic C#
pausing-and-resuming-threadsstandard/threading

Async and concurrency

Pausing and interrupting threads

Learn how to pause & interrupt threads in .NET. Learn how to use methods like Thread.Sleep & Thread.Interrupt, & exceptions such as ThreadInterruptedException.

  • page standard/threading/pausing-and-resuming-threads
  • updated 03/13/2026

The most common ways to synchronize the activities of threads are to block and release threads, or to lock objects or regions of code. For more information on these locking and blocking mechanisms, see Overview of Synchronization Primitives.

You can also have threads put themselves to sleep. When threads are blocked or sleeping, you can use a System.Threading.ThreadInterruptedException to break them out of their wait states.

The Thread.Sleep method

Calling the System.Threading.Thread.Sleep method causes the current thread to immediately block for the number of milliseconds or the time interval you pass to the method, and yields the remainder of its time slice to another thread. Once that interval elapses, the sleeping thread resumes execution.

One thread cannot call System.Threading.Thread.Sleep on another thread. System.Threading.Thread.Sleep is a static method that always causes the current thread to sleep.

Calling System.Threading.Thread.Sleep with a value of System.Threading.Timeout.Infinite causes a thread to sleep until another thread calls the System.Threading.Thread.Interrupt method on the sleeping thread. The following example illustrates interrupting a sleeping thread.

sample · csharpdocs/standard/threading/snippets/pausing-and-resuming-threads/csharp/InterruptThread/Program.csSnippet1

csharp
// <Snippet1>
using System;
using System.Threading;

public class Example
{
    public static void Main()
    {
        // Interrupt a sleeping thread.
        var sleepingThread = new Thread(SleepIndefinitely);
        sleepingThread.Name = "Sleeping";
        sleepingThread.Start();
        Thread.Sleep(2000);
        sleepingThread.Interrupt();
        sleepingThread.Join();
    }

    private static void SleepIndefinitely()
    {
        Console.WriteLine($"Thread '{Thread.CurrentThread.Name}' about to sleep indefinitely.");
        try
        {
            Thread.Sleep(Timeout.Infinite);
        }
        catch (ThreadInterruptedException)
        {
            Console.WriteLine($"Thread '{Thread.CurrentThread.Name}' awoken.");
        }
        finally
        {
            Console.WriteLine($"Thread '{Thread.CurrentThread.Name}' executing finally block.");
        }
        Console.WriteLine($"Thread '{Thread.CurrentThread.Name}' finishing normal execution.");
        Console.WriteLine();
    }
}
// The example displays the following output:
//       Thread 'Sleeping' about to sleep indefinitely.
//       Thread 'Sleeping' awoken.
//       Thread 'Sleeping' executing finally block.
//       Thread 'Sleeping' finishing normal execution.
// </Snippet1>

sample · vbdocs/standard/threading/snippets/pausing-and-resuming-threads/vb/InterruptThread/Program.vbSnippet1

vb
' <Snippet1>
Imports System.Threading

Module Example
    Public Sub Main()
        ' Interrupt a sleeping thread.
        Dim sleepingThread = New Thread(AddressOf SleepIndefinitely)
        sleepingThread.Name = "Sleeping"
        sleepingThread.Start()
        Thread.Sleep(2000)
        sleepingThread.Interrupt()
        sleepingThread.Join()
    End Sub

    Private Sub SleepIndefinitely()
        Console.WriteLine("Thread '{0}' about to sleep indefinitely.",
                          Thread.CurrentThread.Name)
        Try
            Thread.Sleep(Timeout.Infinite)
        Catch ex As ThreadInterruptedException
            Console.WriteLine("Thread '{0}' awoken.",
                              Thread.CurrentThread.Name)
        Finally
            Console.WriteLine("Thread '{0}' executing finally block.",
                              Thread.CurrentThread.Name)
        End Try
        Console.WriteLine("Thread '{0}' finishing normal execution.",
                          Thread.CurrentThread.Name)
        Console.WriteLine()
    End Sub
End Module
' The example displays the following output:
'       Thread 'Sleeping' about to sleep indefinitely.
'       Thread 'Sleeping' awoken.
'       Thread 'Sleeping' executing finally block.
'       Thread 'Sleeping' finishing normal execution.
' </Snippet1>

The example calls System.Threading.Thread.Join to block the calling thread until the interrupted thread finishes execution.

Interrupting threads

You can interrupt a waiting thread by calling the System.Threading.Thread.Interrupt method on the blocked thread to throw a System.Threading.ThreadInterruptedException, which breaks the thread out of the blocking call. The thread should catch the System.Threading.ThreadInterruptedException and do whatever is appropriate to continue working. If the thread ignores the exception, the runtime catches the exception and stops the thread.

If a wait is a managed wait, then System.Threading.Thread.Interrupt wakes the thread immediately. If a wait is an unmanaged wait (for example, a platform invoke call to the Win32 WaitForSingleObject function), System.Threading.Thread.Interrupt can't take control of the thread until it returns to or calls into managed code. In managed code, the behavior is as follows:

See also