thread-abort-migration
Was er macht
Dieser Skill überführt .NET-Framework-Code, der Thread.Abort verwendet, in den Abbruchansatz des modernen .NET. Er ist für Entwickler gedacht, die ältere Apps portieren, deren Code zum Stoppen von Threads nach einem Upgrade nicht mehr funktioniert.
Wann du ihn nutzt
- ✓Wenn ein Projekt, das auf .NET 6 oder neuer umzieht, Thread.Abort aufruft, was jetzt fehlschlägt.
- ✓Wenn Code ThreadAbortException abfängt oder Thread.ResetAbort für den Kontrollfluss nutzt.
- ✓Wenn alter ASP.NET-Code mit Response.End oder Response.Redirect auf modernem .NET laufen muss.
Link zum Skill
https://github.com/dotnet/skills/blob/main/plugins/dotnet-upgrade/skills/thread-abort-migration/SKILL.mdKopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.
So nutzt du ihn
Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.
Fertige Nachricht zum Einfügen
Für Claude Code, Codex oder Cursor: Führe den Befehl in deinem Projektordner aus, dann wird der Skill installiert.
Lade die SKILL.md herunter und lege sie in den Skills-Ordner deines Agenten.
Beispielanfrage an deine KI
“Nach dem Upgrade auf .NET 8 schlägt mein Code bei Thread.Abort fehl. Wie ersetze ich das durch Abbruch?”
5 neue Skills pro Woche. 1 Minute Lesezeit.
So funktioniert es
Der Agent findet heraus, wie der Code Thread.Abort nutzt, erkennt das Nutzungsmuster und wendet die passende Ersetzung an, etwa kooperativen Abbruch.
Technischer Inhalt (originale SKILL.md)
Originaltext des Autors, auf Englisch, direkt von 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
ThreadAbortExceptioncatch blocks that use control flow or cleanup logic - Removing
Thread.ResetAbortcalls that cancel pending aborts - Replacing
Thread.Interruptfor waking blocked threads - Migrating ASP.NET code that uses
Response.EndorResponse.Redirect(url, true), which internally callThread.Abort - Resolving
PlatformNotSupportedExceptionorSYSLIB0006warnings after a target framework change
When Not to Use
- The code only uses
Thread.Join,Thread.Sleep, orThread.Startwithout any abort, interrupt, orThreadAbortExceptioncatch 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.Abortandthread.Abort()(instance calls)ThreadAbortExceptionin catch blocksThread.ResetAbortThread.InterruptResponse.End()(calls Thread.Abort internally in ASP.NET Framework)Response.Redirect(url, true)(thetrueparameter triggers Thread.Abort)SYSLIB0006pragma 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
Häufige Fragen
Kann modernes .NET einen Thread noch erzwungen stoppen?
Nein. Modernes .NET unterstützt das erzwungene Beenden eines verwalteten Threads nicht. Deshalb ist kooperativer Abbruch der Weg.
Braucht Code, der nur Thread.Sleep verwendet, Änderungen?
Nein. Einfache Nutzungen von Join, Sleep und Start funktionieren gleich, und der Skill sagt, dass dafür keine Migration nötig ist.
Schlägt er auch vor, Tasks zu modernisieren?
Er kann optionale Verbesserungen vorschlagen, kennzeichnet sie aber als getrennt von der Thread.Abort-Korrektur.
Details
Originalbeschreibung des Autors
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
Beliebtheit
- GitHub-Sterne
- 5.8k
- Platz im Ranking
- #14649
- Lizenz
- MIT
- Aktualisiert
- 2.11.2026
Kommentare
- …
Weitere Skills aus diesem Repository
create-custom-agent
5.8kHilft deinem Agenten, Agenten-Dateien für VS Code zu erstellen, mit eigenen Werkzeugen, Anweisungen und Übergaben an andere Agenten.
create-skill
5.8kHilft deinem Agenten, einen neuen Agenten-Skill mit gültigem Namen, klarer Auslöserbeschreibung und einer SKILL.md-Datei nach dem Standard zu erstellen.
csharp-scripts
5.8kHilft deinem Agenten, ein kleines C#-Programm als einzelne Datei mit dem .NET-Kommandozeilen-Tool auszuführen, ohne ein vollständiges Projekt anzulegen.
dotnet-pinvoke
5.8kHilft deinem Agenten, native C- oder C++-Bibliotheken korrekt aus .NET aufzurufen, mit Signaturen, Zeichenkettenbehandlung, Speicher und sicheren Handles.
Ähnliche Skills
api-connector-builder
280kLässt deinen Agenten neue API-Anbindungen nach dem bestehenden Muster bauen. Nutze es, wenn du eine weitere Integration ergänzen willst, ohne neue Wege einzuführen.
api-design
280kHilft deinem Agenten, REST-APIs nach Best Practices zu entwerfen. Nützlich für die Kommunikation, die Fehlerausgabe und die Organisation von Daten.
backend-patterns
280kHilft deinem Agenten bei Architekturmustern für die Serverseite und bei der Datenbankoptimierung. Nützlich zum Bauen und Prüfen von Server-Code.