diff --git a/docs/core/compatibility/3.1-5.0.md b/docs/core/compatibility/3.1-5.0.md index 006adef1f4dab..3b999091abe93 100644 --- a/docs/core/compatibility/3.1-5.0.md +++ b/docs/core/compatibility/3.1-5.0.md @@ -150,6 +150,7 @@ If you're migrating from version 3.1 of .NET Core, ASP.NET Core, or EF Core to v ## Core .NET libraries +- [Thread.Abort is obsolete](#threadabort-is-obsolete) - [Obsolete properties on ConsoleLoggerOptions](#obsolete-properties-on-consoleloggeroptions) - [Hardware intrinsic IsSupported checks may differ for nested types](#hardware-intrinsic-issupported-checks-may-differ-for-nested-types) - [Parameter names changed in reference assemblies](#parameter-names-changed-in-reference-assemblies) @@ -168,6 +169,10 @@ If you're migrating from version 3.1 of .NET Core, ASP.NET Core, or EF Core to v - [CounterSet.CreateCounterSetInstance now throws InvalidOperationException if instance already exist](#countersetcreatecountersetinstance-now-throws-invalidoperationexception-if-instance-already-exists) - [Microsoft.DotNet.PlatformAbstractions package removed](#microsoftdotnetplatformabstractions-package-removed) +[!INCLUDE [thread-abort-obsolete](../../../includes/core-changes/corefx/5.0/thread-abort-obsolete.md)] + +*** + [!INCLUDE [obsolete-consoleloggeroptions-properties](../../../includes/core-changes/corefx/5.0/obsolete-consoleloggeroptions-properties.md)] *** diff --git a/docs/core/compatibility/corefx.md b/docs/core/compatibility/corefx.md index 174ed24bfaa6d..c47ee4b8ca63c 100644 --- a/docs/core/compatibility/corefx.md +++ b/docs/core/compatibility/corefx.md @@ -11,6 +11,7 @@ The following breaking changes are documented on this page: | Breaking change | Version introduced | | - | :-: | +| [Thread.Abort is obsolete](#threadabort-is-obsolete) | 5.0 | | [Obsolete properties on ConsoleLoggerOptions](#obsolete-properties-on-consoleloggeroptions) | 5.0 | | [Hardware intrinsic IsSupported checks may differ for nested types](#hardware-intrinsic-issupported-checks-may-differ-for-nested-types) | 5.0 | | [Parameter names changed in reference assemblies](#parameter-names-changed-in-reference-assemblies) | 5.0 | @@ -47,6 +48,10 @@ The following breaking changes are documented on this page: ## .NET 5.0 +[!INCLUDE [thread-abort-obsolete](../../../includes/core-changes/corefx/5.0/thread-abort-obsolete.md)] + +*** + [!INCLUDE [obsolete-consoleloggeroptions-properties](../../../includes/core-changes/corefx/5.0/obsolete-consoleloggeroptions-properties.md)] *** diff --git a/includes/core-changes/corefx/5.0/thread-abort-obsolete.md b/includes/core-changes/corefx/5.0/thread-abort-obsolete.md new file mode 100644 index 0000000000000..075ecced7b38a --- /dev/null +++ b/includes/core-changes/corefx/5.0/thread-abort-obsolete.md @@ -0,0 +1,76 @@ +### Thread.Abort is obsolete + +The APIs are obsolete. Projects that target .NET 5.0 or a later version will encounter compile-time warnings if these methods are called. If you suppress the warnings, a will be thrown at run time. + +#### Change description + +Previously, calls to did not produce compile-time warnings, however, the method did throw a at run time. + +Starting in .NET 5.0, is marked obsolete as warning. Calling this method produces compiler warning `SYSLIB0006`. The implementation of the method is unchanged, and it continues to throw a . + +#### Reason for change + +Given that always throws a on all .NET implementations except .NET Framework, was added to the method to draw attention to places where it's called. + +#### Version introduced + +5.0 RC 1 + +#### Recommended action + +- Use a to abort processing of a unit of work instead of calling . The following example illustrates the use of . + + ```csharp + void ProcessPendingWorkItemsNew(CancellationToken cancellationToken) + { + if (QueryIsMoreWorkPending()) + { + // If the CancellationToken is marked as "needs to cancel", + // this will throw the appropriate exception. + cancellationToken.ThrowIfCancellationRequested(); + + WorkItem work = DequeueWorkItem(); + ProcessWorkItem(work); + } + } + ``` + + For more information, see [Cancellation in managed threads](../../../../docs/standard/threading/cancellation-in-managed-threads.md). + +- To suppress the compile-time warning, suppress warning code `SYSLIB0006`. The warning code is specific to and suppressing it doesn't suppress other obsoletion warnings in your code. However, we recommend that you remove calls to instead of suppressing the warning. + + ```csharp + void MyMethod() + { + #pragma warning disable SYSLIB0006 + Thread.CurrentThread.Abort(); + #pragma warning restore SYSLIB0006 + } + ``` + + You can also suppress the warning in the project file. + + ```xml + + Exe + net5.0 + + $(NoWarn);SYSLIB0006 + + ``` + +#### Category + +- Core .NET libraries + +#### Affected APIs + +- + +