Skip to content
Code quality and reliability Reviewed 2026-09-13

Thread Suspend Resume

What does this mean ?

Thread.Suspend and Thread.Resume are obsolete synchronization APIs. Suspension can stop a worker while it owns resources other threads need. In .NET Core and .NET 5+, Suspend throws PlatformNotSupportedException, as documented by Microsoft.

What can happen ?

Older applications may deadlock or stall indefinitely; modern applications may fail immediately on the unsupported call. This is an availability and lifecycle problem, with severity depending on who can trigger the affected workflow.

Recommendation

For shutdown, request cooperative cancellation and await worker completion. Every potentially long operation must observe the token or have its own bounded timeout. Cancellation does not forcibly interrupt arbitrary blocking code and is not resumable suspension. If pause/resume is required, design explicit checkpoints or a control queue so pausing occurs outside critical sections. Keep cleanup in finally or using scopes.

Sample Code

Unsafe legacy external suspension:

worker.Suspend();
worker.Resume();

Cooperative worker shutdown:

static async Task RunAsync(
    Func<CancellationToken, Task> work, CancellationToken stopping)
{
    while (true)
    {
        stopping.ThrowIfCancellationRequested();
        await work(stopping);
        await Task.Delay(100, stopping);
    }
}

The caller owns a CancellationTokenSource, passes its token, calls Cancel(), then awaits the task and handles expected cancellation. Unexpected exceptions must still be reported. The delegate must honor cancellation; this wrapper cannot guarantee prompt completion if it does not.

Regression test: a pre-canceled token must prevent any work. Cancel a running cooperative operation, await cancellation within a timeout, and confirm its cleanup executes. Test pause semantics separately if the application requires them.

References