From dotnet-upgrade
Migrates .NET Framework Thread.Abort, ThreadAbortException handling, Thread.Interrupt, and ASP.NET Response.End/Redirect to cooperative cancellation in .NET 6+. Resolves migration exceptions.
npx claudepluginhub dotnet/skills --plugin dotnet-upgradeThis skill uses the workspace's default tool permissions.
This skill helps an agent migrate .NET Framework code that uses `Thread.Abort` to the cooperative cancellation model required by modern .NET (6+). `Thread.Abort` throws `PlatformNotSupportedException` in modern .NET — there is no way to forcibly terminate a managed thread. The skill identifies the usage pattern first, then applies the correct replacement strategy.
Guides Next.js Cache Components and Partial Prerendering (PPR) with cacheComponents enabled. Implements 'use cache', cacheLife(), cacheTag(), revalidateTag(), static/dynamic optimization, and cache debugging.
Migrates code, prompts, and API calls from Claude Sonnet 4.0/4.5 or Opus 4.1 to Opus 4.5, updating model strings on Anthropic, AWS, GCP, Azure platforms.
Automates semantic versioning and release workflow for Claude Code plugins: bumps versions in package.json, marketplace.json, plugin.json; verifies builds; creates git tags, GitHub releases, changelogs.
This skill helps an agent migrate .NET Framework code that uses Thread.Abort to the cooperative cancellation model required by modern .NET (6+). Thread.Abort throws PlatformNotSupportedException in modern .NET — there is no way to forcibly terminate a managed thread. The skill identifies the usage pattern first, then applies the correct replacement strategy.
Thread.AbortThreadAbortException catch blocks that use control flow or cleanup logicThread.ResetAbort calls that cancel pending abortsThread.Interrupt for waking blocked threadsResponse.End or Response.Redirect(url, true), which internally call Thread.AbortPlatformNotSupportedException or SYSLIB0006 warnings after a target framework changeThread.Join, Thread.Sleep, or Thread.Start without any abort, interrupt, or ThreadAbortException catch blocks. These APIs work identically in modern .NET — no migration is needed. Stop here and tell the user no migration is required. If you suggest modernization (e.g., Task.Run, Parallel.ForEach), you must explicitly state these are optional improvements unrelated to Thread.Abort migration, and the existing code will compile and run correctly as-is on the target framework.| 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., net8.0) |
| Thread.Abort usage locations | Recommended | Files or classes that reference Thread.Abort, ThreadAbortException, Thread.ResetAbort, or Thread.Interrupt |
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.
Search the codebase for all thread-termination-related APIs:
Thread.Abort and thread.Abort() (instance calls)ThreadAbortException in catch blocksThread.ResetAbortThread.InterruptResponse.End() (calls Thread.Abort internally in ASP.NET Framework)Response.Redirect(url, true) (the true parameter triggers Thread.Abort)SYSLIB0006 pragma suppressionsRecord each usage location and classify the intent behind the abort.
Categorize every usage into one of the following patterns:
| Pattern | Description | Modern replacement |
|---|---|---|
| Cancellable work loop | Thread running a loop that should stop on demand | CancellationToken checked in the loop |
| Timeout enforcement | Aborting a thread that exceeds a time limit | CancellationTokenSource.CancelAfter or Task.WhenAny with a delay |
| Blocking call interruption | Thread blocked on Sleep, WaitOne, or Join that needs to wake up | WaitHandle.WaitAny with CancellationToken.WaitHandle, or async alternatives |
| ASP.NET request termination | Response.End or Response.Redirect(url, true) | Return from the action method; use HttpContext.RequestAborted |
| ThreadAbortException as control flow | Catch blocks that inspect ThreadAbortException to decide cleanup actions | Catch OperationCanceledException instead, with explicit cleanup |
| Thread.ResetAbort to continue execution | Catching the abort and calling ResetAbort to keep the thread alive | Check CancellationToken.IsCancellationRequested and decide whether to continue |
| 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 Process.Kill |
Critical: The fundamental paradigm shift is from preemptive cancellation (the runtime forcibly injects an exception) to cooperative cancellation (the code must voluntarily check for and respond to cancellation requests). Every call site must be evaluated for whether the target code can be modified to cooperate.
CancellationToken parameter. Replace the loop condition or add token.ThrowIfCancellationRequested() at safe checkpoints. The caller creates a CancellationTokenSource and calls Cancel() instead of Thread.Abort().new CancellationTokenSource(TimeSpan.FromSeconds(n)) or cts.CancelAfter(timeout). Pass the token to the work. For task-based code, use Task.WhenAny(workTask, Task.Delay(timeout, cts.Token)) and cancel the source if the delay wins; cancelling also disposes the delay's internal timer.Thread.Sleep(ms) with Task.Delay(ms, token) or token.WaitHandle.WaitOne(ms). Replace ManualResetEvent.WaitOne() with WaitHandle.WaitAny(new[] { event, token.WaitHandle }).Response.End() entirely — just return from the method. Replace Response.Redirect(url, true) with Response.Redirect(url) (without the true endResponse parameter) or return a redirect result. In ASP.NET Core, use HttpContext.RequestAborted as the cancellation token for long-running request work.catch (ThreadAbortException) with catch (OperationCanceledException). Move cleanup logic to finally blocks or CancellationToken.Register callbacks. Do not catch OperationCanceledException and swallow it — let it propagate unless you have a specific recovery action.ResetAbort to prevent tearing down the thread. Check token.IsCancellationRequested after each unit and decide whether to continue. Create a new CancellationTokenSource (optionally linked to a parent token) for each new unit of work rather than trying to reset an existing one.CancellationToken (e.g., third-party library, native call), move the work to a child process. The host process communicates via stdin/stdout or IPC and calls Process.Kill if a timeout expires.After migrating all patterns, remove or replace any remaining references:
| Removed API | Replacement |
|---|---|
Thread.Abort() | CancellationTokenSource.Cancel() |
ThreadAbortException catch blocks | OperationCanceledException catch blocks |
Thread.ResetAbort() | Check token.IsCancellationRequested and decide whether to continue |
Thread.Interrupt() | Signal via CancellationToken or set a ManualResetEventSlim (also obsolete: SYSLIB0046 in .NET 9) |
Response.End() | Remove the call; return from the method |
Response.Redirect(url, true) | Response.Redirect(url) without endResponse, or return a redirect result |
#pragma warning disable SYSLIB0006 | Remove after replacing the Thread.Abort call |
SYSLIB0006 warnings and no Thread.Abort-related compile errors.Thread.Abort, ThreadAbortException, Thread.ResetAbort, or Thread.Interrupt.Thread.Abort for cleanup or timeout, update them to use CancellationToken.Thread.Abort remain in the migrated codeThreadAbortException catch blocks remainThread.ResetAbort calls remainSYSLIB0006 pragma suppressions remainCancellationToken parameterCancellationTokenSource.CancelAfter or equivalentWaitHandle.WaitAny with token.WaitHandle or async alternatives| Pitfall | Solution |
|---|---|
Adding CancellationToken parameter but never checking it in long-running code | Insert token.ThrowIfCancellationRequested() at regular checkpoints in loops and between expensive operations. Cancellation only works if the code cooperates. |
| Not passing the token through the full call chain | Every async or long-running method in the chain must accept and forward the CancellationToken. If one method in the chain ignores it, cancellation stalls at that point. |
Expecting CancellationToken to interrupt blocking synchronous calls like Thread.Sleep or socket.Receive | These calls do not check the token. Replace Thread.Sleep(ms) with token.WaitHandle.WaitOne(ms). Replace synchronous I/O with async overloads that accept a CancellationToken. |
Catching OperationCanceledException and swallowing it | Let OperationCanceledException propagate to the caller. Only catch it at the top-level orchestration point where you decide what to do after cancellation (log, clean up, return a result). |
Not disposing CancellationTokenSource | CancellationTokenSource is IDisposable. Wrap it in a using statement or dispose it in a finally block. Leaking it causes timer and callback leaks. |
| 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 Thread.Interrupt as a substitute for Thread.Abort | Thread.Interrupt is also not recommended in modern .NET. It only works on threads in WaitSleepJoin state and throws ThreadInterruptedException, which is a different exception type. Replace with CancellationToken signaling. |
Removing ThreadAbortException catch blocks without migrating the cleanup logic | ThreadAbortException catch blocks often contained critical cleanup (releasing locks, rolling back transactions). Move this logic to finally blocks or CancellationToken.Register callbacks before removing the catch. |
Thread.Abort throws PlatformNotSupportedExceptionCancellationTokenThread.Abort is obsoleteThread.Interrupt is obsolete (added in .NET 9)Task.WaitAsync(CancellationToken) — cancellable waiting for task-based code (.NET 6+)