Loading...
Loading...
Guides migration of .NET Framework Thread.Abort usage to cooperative cancellation in modern .NET. USE FOR: modernizing code that calls Thread.Abort, catching ThreadAbortException, replacing Thread.ResetAbort, replacing Thread.Interrupt for thread termination, resolving PlatformNotSupportedException or SYSLIB0006 after retargeting to .NET 6+, migrating ASP.NET Response.End or Response.Redirect(url, true) which internally call Thread.Abort. DO NOT USE FOR: code that only uses Thread.Join, Thread.Sleep, or Thread.Start without any abort, interrupt, or ThreadAbortException usage — these APIs work identically in modern .NET and need no migration. Also not for projects staying on .NET Framework, or Thread.Abort usage inside third-party libraries you do not control.
npx skill4agent add dotnet/skills thread-abort-migrationThread.AbortThread.AbortPlatformNotSupportedExceptionThread.AbortThreadAbortExceptionThread.ResetAbortThread.InterruptResponse.EndResponse.Redirect(url, true)Thread.AbortPlatformNotSupportedExceptionSYSLIB0006Thread.JoinThread.SleepThread.StartThreadAbortExceptionTask.RunParallel.ForEach| Input | Required | Description |
|---|---|---|
| Source project or solution | Yes | The .NET Framework project containing Thread.Abort usage |
| Target framework | Yes | The modern .NET version to target (e.g., |
| Thread.Abort usage locations | Recommended | Files or classes that reference |
Commit strategy: Commit after each pattern replacement so the migration is reviewable and bisectable. Group related call sites (e.g., all cancellable work loops) into one commit.
Thread.Abortthread.Abort()ThreadAbortExceptionThread.ResetAbortThread.InterruptResponse.End()Response.Redirect(url, true)trueSYSLIB0006| Pattern | Description | Modern replacement |
|---|---|---|
| Cancellable work loop | Thread running a loop that should stop on demand | |
| Timeout enforcement | Aborting a thread that exceeds a time limit | |
| Blocking call interruption | Thread blocked on | |
| ASP.NET request termination | | Return from the action method; use |
| ThreadAbortException as control flow | Catch blocks that inspect | Catch |
| Thread.ResetAbort to continue execution | Catching the abort and calling | Check |
| Uncooperative code termination | Killing a thread running code that cannot be modified to check for cancellation | Move the work to a separate process and use |
CancellationTokentoken.ThrowIfCancellationRequested()CancellationTokenSourceCancel()Thread.Abort()new CancellationTokenSource(TimeSpan.FromSeconds(n))cts.CancelAfter(timeout)Task.WhenAny(workTask, Task.Delay(timeout, cts.Token))Thread.Sleep(ms)Task.Delay(ms, token)token.WaitHandle.WaitOne(ms)ManualResetEvent.WaitOne()WaitHandle.WaitAny(new[] { event, token.WaitHandle })Response.End()Response.Redirect(url, true)Response.Redirect(url)trueHttpContext.RequestAbortedcatch (ThreadAbortException)catch (OperationCanceledException)finallyCancellationToken.RegisterOperationCanceledExceptionResetAborttoken.IsCancellationRequestedCancellationTokenSourceCancellationTokenProcess.Kill| Removed API | Replacement |
|---|---|
| |
| |
| Check |
| Signal via |
| Remove the call; return from the method |
| |
| Remove after replacing the Thread.Abort call |
SYSLIB0006Thread.AbortThread.AbortThreadAbortExceptionThread.ResetAbortThread.InterruptThread.AbortCancellationTokenThread.AbortThreadAbortExceptionThread.ResetAbortSYSLIB0006CancellationTokenCancellationTokenSource.CancelAfterWaitHandle.WaitAnytoken.WaitHandle| Pitfall | Solution |
|---|---|
Adding | Insert |
| Not passing the token through the full call chain | Every async or long-running method in the chain must accept and forward the |
Expecting | These calls do not check the token. Replace |
Catching | Let |
Not disposing | |
| Assuming cancellation is immediate | Cooperative cancellation only takes effect at the next checkpoint. If work items are large or the code has long gaps between checks, cancellation may be delayed. Design checkpoint frequency based on acceptable latency. |
Using | |
Removing | |
Thread.AbortPlatformNotSupportedExceptionCancellationTokenThread.AbortThread.InterruptTask.WaitAsync(CancellationToken)