Breaking change: Thread.Abort is now obsolete #19625
Labels
breaking-change
Indicates a .NET Core breaking change
🏁 Release: .NET 5
Work items for the .NET 5 release
doc-idea
Indicates issues that are suggestions for new topics [org][type][category]
Thread.Abort is now obsolete
The
Thread.Abort
APIs are now obsolete. Code targeting .NET 5.0+ will receive compile-time warnings when these methods are called. If the warning is suppressed and these methods are called, they will throwPlatformNotSupportedException
at runtime.Version introduced
.NET 5.0 RC1
Old behavior
Calls to
Thread.Abort
would not produce compile-time warnings. However, on all versions of .NET Core, they would throw exceptions at runtime.New behavior
Beginning with .NET 5.0,
Thread.Abort
is marked obsolete as warning. The runtime implementation of the method is unchanged: it continues to throwPlatformNotSupportedException
.Reason for change
Thread.Abort
always throwsPlatformNotSupportedException
on all .NET Core and .NET 5.0+ runtimes. We annotated the API with[Obsolete]
to help draw attention to this so that developers can remove these call sites from their own code bases.Recommended action
If you are trying to abort processing a unit of work, consider using
CancellationToken
, as demonstrated below.For more information on using
CancellationToken
to support graceful cancellation, see the document "Cancellation in Managed Threads".If you need to suppress this warning in code, you can do so by suppressing the warning code
SYSLIB0006
. This warning code is specific toThread.Abort
and will not suppress other obsoletion warnings in your code. We recommend removing such call sites from your own code.This can also be suppressed project-wide via the .csproj.
Category
Affected APIs
System.Threading.Thread.Abort
(all overloads)Issue metadata
The text was updated successfully, but these errors were encountered: