thread-abort-migration

Migrates .NET Framework Thread.Abort usage to cooperative CancellationToken patterns in modern .NET.

Updated Jul 12, 2026
One-click install
npx skills add https://github.com/Patrick-Rex/DotNetTechSamples --skill thread-abort-migration-patrick-rex
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: thread-abort-migration
Source: https://github.com/Patrick-Rex/DotNetTechSamples/tree/main/.agents/plugins/dotnet-upgrade/skills/thread-abort-migration
Command: npx skills add https://github.com/Patrick-Rex/DotNetTechSamples --skill thread-abort-migration-patrick-rex

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Thread.Abort throws PlatformNotSupportedException in .NET 6+, breaking legacy .NET Framework code that relies on forcible thread termination. This Skill guides the migration of Thread.Abort, ThreadAbortException, Thread.ResetAbort, and Thread.Interrupt usage to the cooperative cancellation model based on CancellationToken. ## Core Features & Use Cases - Usage Inventory and Classification: Scans the codebase for all thread-termination APIs and classifies each call site into patterns such as cancellable work loops, timeout enforcement, blocking call interruption, and ASP.NET request termination. - Pattern-Based Replacement: Applies the correct modern replacement per pattern, including CancellationTokenSource.CancelAfter for timeouts, WaitHandle.WaitAny with token.WaitHandle for blocking calls, and OperationCanceledException for control flow. - ASP.NET Migration: Replaces Response.End and Response.Redirect(url, true), which internally call Thread.Abort, with early returns and HttpContext.RequestAborted. - Use Case: After retargeting a legacy application to net8.0, you hit SYSLIB0006 warnings and runtime PlatformNotSupportedException. This Skill walks through each Thread.Abort call site, applies the cooperative cancellation replacement, and verifies the build is clean. ## Quick Start Migrate all Thread.Abort usage in my .NET Framework project to cooperative cancellation targeting net8.0.

Frequently Asked Questions about thread-abort-migration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I replace Thread.Abort in .NET 6 or later?

Replace Thread.Abort with cooperative cancellation using CancellationToken. Pass a CancellationToken into the worker method, check it with token.ThrowIfCancellationRequested() at safe checkpoints, and call CancellationTokenSource.Cancel() instead of Abort().

How to fix PlatformNotSupportedException for Thread.Abort after upgrading to .NET 8?

The exception occurs because Thread.Abort is unsupported in modern .NET. Inventory all Thread.Abort, ThreadAbortException, and Thread.ResetAbort call sites, classify each by intent, and migrate them to CancellationToken-based patterns, then verify the build has no SYSLIB0006 warnings.

What replaces ThreadAbortException catch blocks in modern .NET?

Replace catch (ThreadAbortException) with catch (OperationCanceledException). Move critical cleanup logic into finally blocks or CancellationToken.Register callbacks, and let OperationCanceledException propagate rather than swallowing it.

Does Response.Redirect(url, true) work in ASP.NET Core?

No. The true endResponse parameter internally calls Thread.Abort in classic ASP.NET. In ASP.NET Core, call Response.Redirect(url) without the parameter or return a redirect result, and use HttpContext.RequestAborted as the cancellation token for long-running request work.

When is Thread.Abort migration not needed?

No migration is needed if the code only uses Thread.Join, Thread.Sleep, or Thread.Start without any abort, interrupt, or ThreadAbortException usage, since those APIs work identically in modern .NET. It also does not apply to projects staying on .NET Framework.

How do I cancel code that cannot accept a CancellationToken?

For uncooperative code such as third-party libraries or native calls, move the work into a separate child process. Communicate via stdin/stdout or IPC and call Process.Kill if a timeout expires, since cooperative cancellation cannot reach code you cannot modify.