From 1015460e0de40f8a6af29a37fa038a958a259ea5 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 6 Aug 2020 08:07:00 -0700 Subject: [PATCH] fixes #19625 --- docs/core/compatibility/3.1-5.0.md | 5 ++ docs/core/compatibility/corefx.md | 5 ++ .../corefx/5.0/thread-abort-obsolete.md | 76 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 includes/core-changes/corefx/5.0/thread-abort-obsolete.md diff --git a/docs/core/compatibility/3.1-5.0.md b/docs/core/compatibility/3.1-5.0.md index b0eccb9bffd18..0e88b83b6e2d2 100644 --- a/docs/core/compatibility/3.1-5.0.md +++ b/docs/core/compatibility/3.1-5.0.md @@ -122,6 +122,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) - [PrincipalPermissionAttribute is obsolete as error](#principalpermissionattribute-is-obsolete-as-error) - [BinaryFormatter serialization methods are obsolete and prohibited in ASP.NET apps](#binaryformatter-serialization-methods-are-obsolete-and-prohibited-in-aspnet-apps) - [UTF-7 code paths are obsolete](#utf-7-code-paths-are-obsolete) @@ -132,6 +133,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 [principalpermissionattribute-obsolete](../../../includes/core-changes/corefx/5.0/principalpermissionattribute-obsolete.md)] *** diff --git a/docs/core/compatibility/corefx.md b/docs/core/compatibility/corefx.md index 724691a96b049..3f8d277788562 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 | | [PrincipalPermissionAttribute is obsolete as error](#principalpermissionattribute-is-obsolete-as-error) | 5.0 | | [BinaryFormatter serialization methods are obsolete and prohibited in ASP.NET apps](#binaryformatter-serialization-methods-are-obsolete-and-prohibited-in-aspnet-apps) | 5.0 | | [UTF-7 code paths are obsolete](#utf-7-code-paths-are-obsolete) | 5.0 | @@ -39,6 +40,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 [principalpermissionattribute-obsolete](../../../includes/core-changes/corefx/5.0/principalpermissionattribute-obsolete.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 + +- + +