本文へスキップ
Skillpedia
APIとサーバー(バックエンド)5.8k · #14649

thread-abort-migration

できること

このスキルは、Thread.Abortを使う.NET Frameworkのコードを、最新の.NETで使われるキャンセルの方法に移します。アップグレード後にスレッドを止めるコードが動かなくなった、古いアプリを移植する開発者向けです。

使う場面

  • ✓.NET 6以降に移行するプロジェクトが、今では失敗するThread.Abortを呼んでいるとき。
  • ✓コードがThreadAbortExceptionを捕まえたり、Thread.ResetAbortを制御の流れに使ったりしているとき。
  • ✓Response.EndやResponse.Redirectを使う古いASP.NETのコードを、最新の.NETで動かす必要があるとき。

スキルのリンク

https://github.com/dotnet/skills/blob/main/plugins/dotnet-upgrade/skills/thread-abort-migration/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/dotnet/skills/blob/main/plugins/dotnet-upgrade/skills/thread-abort-migration/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“.NET 8にアップグレードしてから、コードのThread.Abortで失敗します。キャンセルに置き換えるにはどうすればよいですか?”

毎週5つの新しいスキル。1分で読めます。

仕組み

エージェントは、Thread.Abortがコードでどのように使われているかを調べ、その使い方に合った置き換え(協調的なキャンセルなど)を適用します。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

Thread.Abort Migration

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.

When to Use

  • Migrating a .NET Framework project to .NET 6+ that calls Thread.Abort
  • Replacing ThreadAbortException catch blocks that use control flow or cleanup logic
  • Removing Thread.ResetAbort calls that cancel pending aborts
  • Replacing Thread.Interrupt for waking blocked threads
  • Migrating ASP.NET code that uses Response.End or Response.Redirect(url, true), which internally call Thread.Abort
  • Resolving PlatformNotSupportedException or SYSLIB0006 warnings after a target framework change

When Not to Use

  • The code only uses Thread.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.
  • The project will remain on .NET Framework indefinitely
  • The Thread.Abort usage is inside a third-party library you do not control

Inputs

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

Workflow

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.

Step 1: Inventory all thread termination usage

Search the codebase for all thread-termination-related APIs:

  • Thread.Abort and thread.Abort() (instance calls)
  • ThreadAbortException in catch blocks
  • Thread.ResetAbort
  • Thread.Interrupt
  • Response.End() (calls Thread.Abort internally in ASP.NET Framework)
  • Response.Redirect(url, true) (the true parameter triggers Thread.Abort)
  • SYSLIB0006 pragma suppressions

Record each usage location and classify the intent behind the abort.

Step 2: Classify each usage pattern

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.

Step 3: Apply the replacement for each pattern

  • Cancellable work loop: A
よくある質問

最新の.NETでもスレッドを強制的に止められますか?

いいえ。最新の.NETは、管理されたスレッドを強制的に終了することをサポートしていないため、協調的なキャンセルが方法です。

Thread.Sleepだけを使うコードは変更が必要ですか?

いいえ。Join、Sleep、Startの単純な使い方は同じように動くので、移行は不要だとスキルは説明しています。

タスクの近代化も提案しますか?

任意の改善を提案することはありますが、それはThread.Abortの修正とは別だとラベルを付けます。

詳細

作者による元の説明

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

repo: dotnet/skills

人気

GitHubのスター
5.8k
ランキング
#14649
ライセンス
MIT
更新日
2026/11/2

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル