A thread is aborted, suspended or resumed, which can corrupt state or deadlock
What it finds
Thread.Abort raises an exception at an arbitrary point of the target thread, possibly in the middle of updating shared state or holding a lock; Suspend stops it while it may hold a lock. Modern .NET throws PlatformNotSupportedException for them. Cooperative cancellation with a CancellationToken stops a thread at points it chooses.
From the rule's source, thread_abort.rs.
using System.Threading; class Workers{ void Stop(Thread worker) { worker.Abort();tx0 reports: Thread.Abort can stop a thread in the middle of its work Thread.CurrentThread.Suspend();tx0 reports: Thread.Suspend can stop a thread in the middle of its work worker.Join(); }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:thread-abort" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:thread-abort] reason="..."tx0 explain tx0/csharp:thread-abort shows the same in the terminal. Found a false positive? Report it.