Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/core/compatibility/3.1-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)]

***
Expand Down
5 changes: 5 additions & 0 deletions docs/core/compatibility/corefx.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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)]

***
Expand Down
76 changes: 76 additions & 0 deletions includes/core-changes/corefx/5.0/thread-abort-obsolete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
### Thread.Abort is obsolete

The <xref:System.Threading.Thread.Abort%2A?displayProperty=nameWithType> 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 <xref:System.PlatformNotSupportedException> will be thrown at run time.

#### Change description

Previously, calls to <xref:System.Threading.Thread.Abort%2A?displayProperty=nameWithType> did not produce compile-time warnings, however, the method did throw a <xref:System.PlatformNotSupportedException> at run time.

Starting in .NET 5.0, <xref:System.Threading.Thread.Abort%2A?displayProperty=nameWithType> 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 <xref:System.PlatformNotSupportedException>.

#### Reason for change

Given that <xref:System.Threading.Thread.Abort%2A?displayProperty=nameWithType> always throws a <xref:System.PlatformNotSupportedException> on all .NET implementations except .NET Framework, <xref:System.ObsoleteAttribute> was added to the method to draw attention to places where it's called.

#### Version introduced

5.0 RC 1

#### Recommended action

- Use a <xref:System.Threading.CancellationToken> to abort processing of a unit of work instead of calling <xref:System.Threading.Thread.Abort%2A?displayProperty=nameWithType>. The following example illustrates the use of <xref:System.Threading.CancellationToken>.

```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 <xref:System.Threading.Thread.Abort%2A?displayProperty=nameWithType> and suppressing it doesn't suppress other obsoletion warnings in your code. However, we recommend that you remove calls to <xref:System.Threading.Thread.Abort%2A?displayProperty=nameWithType> 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
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<!-- Disable "Thread.Abort is obsolete" warnings for entire project. -->
<NoWarn>$(NoWarn);SYSLIB0006</NoWarn>
</PropertyGroup>
```

#### Category

- Core .NET libraries

#### Affected APIs

- <xref:System.Threading.Thread.Abort%2A?displayProperty=fullName>

<!--

#### Affected APIs

- `Overload:System.Threading.Thread.Abort`

-->