Reviews and safely refactors existing WinForms (.NET Framework) code to fix cross-thread crashes, UI hangs, and memory leaks using a safety checklist. Makes minimal, behavior-preserving changes.
Ships in TheCodeMan .NET AI ToolKit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Keep an existing WinForms app alive and healthy with small, safe, behavior-preserving changes. This is maintenance, not migration: no WPF/MAUI rewrite, no restructuring the whole form. Fix the things that actually cause crashes, hangs, and leaks in long-lived WinForms apps, and leave the rest alone.
You don't need pasted snippets. Work from whatever target the user gives:
MainForm.cs (grab its .Designer.cs too if control setup matters)Forms/ or UI/ directory.csproj / .sln or the repo rootgit clone --depth 1 <url> /tmp/repo && cd /tmp/repoFind the WinForms code yourself with Glob/Grep/Bash instead of asking for a paste:
grep -rl "System.Windows.Forms\|: Form\|InitializeComponent" --include=*.cs <target> | grep -vi "/obj/\|/bin/"
grep -rn "new Thread\|InvokeRequired\|async void\|ShowDialog\|+= " --include=*.cs <target>
Prioritize handlers with cross-thread access, blocking calls, or leaks, and tell the user which forms you scanned.
The user maintains a WinForms app on .NET Framework and wants a specific handler/form reviewed or fixed -- a cross-thread crash, a UI that freezes, a leak, a flaky grid. They paste a Form/UserControl or describe the symptom. If you don't have the code, ask for the handler and the .Designer.cs if control setup is relevant.
Do not propose rewriting to another UI stack or restructuring the form. Every change must be droppable into the existing form with minimal diff. If a real fix requires bigger surgery, describe it and let the user decide -- default to the smallest safe change.
Apply every item. For each finding: problem -> impact -> minimal fix.
Touching a control from a non-UI thread throws InvalidOperationException ("Cross-thread operation not valid").
Thread, Task.Run, BackgroundWorker.DoWork, timer callback, or async continuation that sets .Text, .DataSource, .Items, .Enabled, etc. on a control.async/await -- do the work with await Task.Run(...) and update the UI after the await, which resumes on the UI thread via the sync context. No Invoke needed.if (control.InvokeRequired) control.BeginInvoke(() => control.Text = value); else control.Text = value;. Prefer BeginInvoke (async, won't deadlock) over Invoke (sync, can deadlock if the UI thread is waiting on your worker).Long work on the UI thread makes the window "Not Responding".
Thread.Sleep, big loops directly inside a Click/Load handler; .Result / .Wait() on a Task in a UI handler (also a deadlock risk with the sync context).async and await the work off-thread (await Task.Run(...) for CPU-bound; real async APIs for I/O). Disable the triggering control and show busy state while it runs; re-enable in a finally. Never .Result/.Wait() on the UI thread.new Form() / new SomeDialog() shown without using; Font, Brush, Pen, Bitmap, Graphics created in OnPaint/handlers without disposal; controls added/removed dynamically but never disposed.using var dlg = new EditForm(); dlg.ShowDialog(this);. Dispose GDI objects (Font/Brush/Pen/Bitmap) with using, or cache long-lived ones as fields and dispose in the form's Dispose. Note: controls added to Controls are disposed by the parent -- ones you remove and drop are not.Long-lived publishers keep short-lived subscribers alive via += that's never -='d.
FormClosed/Dispose for every += to an external/long-lived source. (In-form Designer wiring to the form's own controls is fine -- it dies with the form.)DataSource on every refresh causing flicker/reset; editing the grid's backing list directly instead of through a BindingSource; heavy formatting per cell.BindingSource; mutate the list via the BindingSource so the grid updates; for bulk changes SuspendLayout()/ResumeLayout() or set DataSource = null then rebind once. Keep DataTable/DataSet binding if that's what's already load-bearing -- don't swap the data model.async void handlers that can throw -- an unobserved exception crashes the process.async void is acceptable only for event handlers, and only if the whole body is wrapped in try/catch that surfaces errors to the user/log. Everywhere else, async Task.*.Designer.cs.private async void btnLoad_Click(object sender, EventArgs e)
{
btnLoad.Enabled = false; // guard against double-click / re-entry
UseWaitCursor = true;
try
{
// off the UI thread
List<OrderDto> orders = await _service.GetOrdersAsync(_customerId, CancellationToken.None);
// back on the UI thread automatically after await -- safe to touch controls
ordersBindingSource.DataSource = orders;
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message, "Load failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
// and log it -- async void must not let exceptions escape
}
finally
{
UseWaitCursor = false;
btnLoad.Enabled = true;
}
}
## Summary
<one paragraph: crash/hang/leak headline findings>
## Findings
1. [Cross-thread] <handler/line> -- <problem> -> <minimal fix>
2. [UI-thread block] ... -> ...
3. [Leak] ... -> ...
## Patched code
<the minimally changed handler(s), ready to paste>
## Verify on your side
<Designer.cs touch points, threading assumptions, anything needing a run>
InvokeRequired boilerplate; use BeginInvoke when you must marshal..Result on the UI thread. That's freezes and deadlocks.+= to a long-lived source needs a -=. That's your slow leak.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
winforms, dotnet-framework, cross-thread, ui-maintenance, code-review, refactoring
49 skills in this plugin
/adonet-data-access-auditorAudit and fix classic ADO.NET data-access code (SqlConnection / SqlCommand / SqlDataReader / DataSet) on .NET Framework. Use this skill whenever the user shares raw ADO.NET code, a DAL / repository built on SqlCommand, stored-proc calls, string-concatenated SQL, or mentions SQL injection, parameterized queries, connection leaks, "using / Dispose", reading the same column multiple times, transactions, or "why does my old data layer leak connections / is it safe". Always use this skill for classic ADO.NET review instead of answering from memory; it applies a fixed security + correctness + performance checklist and rewrites the code./async-await-auditorAudit C#/.NET code for async/await anti-patterns and concurrency bugs. Use this skill whenever the user shares async C# code or asks about deadlocks, async void, .Result/.Wait(), blocking calls, ConfigureAwait, sync-over-async, fire-and-forget tasks, CancellationToken usage, or "why does my async code hang/deadlock". Always use this skill for async correctness/performance reviews instead of answering from memory; it applies a fixed checklist and rewrites the code./authorization-policy-generatorDesign ASP.NET Core authorization — policy-based, role-based, and claims/requirement-based with custom authorization handlers and resource-based checks. Use this skill whenever the user wants authorization policies, role/claim checks, custom AuthorizationHandler, resource-based authorization, permission checks, or asks "how do I authorize this / policy vs role / restrict this endpoint to X". Always use this skill for authorization requests; it generates policies, handlers, and endpoint wiring./dotnet-ai-toolkit:winforms-maintainerfrom TheCodeMan .NET AI ToolKit
npx claudepluginhub stefanthecode/dotnet-ai-toolkit --plugin dotnet-ai-toolkitOther plugins' skills for the same job