diff --git a/src/libraries/Common/src/System/Threading/Tasks/ForceAsyncAwaiter.cs b/src/libraries/Common/src/System/Threading/Tasks/ForceAsyncAwaiter.cs
deleted file mode 100644
index 9b5d88f5b993ba..00000000000000
--- a/src/libraries/Common/src/System/Threading/Tasks/ForceAsyncAwaiter.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Runtime.CompilerServices;
-
-namespace System.Threading.Tasks
-{
- internal static partial class TaskAwaiters
- {
- ///
- /// Returns an awaitable/awaiter that will ensure the continuation is executed
- /// asynchronously on the thread pool, even if the task is already completed
- /// by the time the await occurs. Effectively, it is equivalent to awaiting
- /// with ConfigureAwait(false) and then queuing the continuation with Task.Run,
- /// but it avoids the extra hop if the continuation already executed asynchronously.
- ///
- public static ForceAsyncAwaiter ForceAsync(this Task task)
- {
- return new ForceAsyncAwaiter(task);
- }
- }
-
- internal readonly struct ForceAsyncAwaiter : ICriticalNotifyCompletion
- {
- private readonly Task _task;
-
- internal ForceAsyncAwaiter(Task task) { _task = task; }
-
- public ForceAsyncAwaiter GetAwaiter() { return this; }
-
- public bool IsCompleted { get { return false; } } // the purpose of this type is to always force a continuation
-
- public void GetResult() { _task.GetAwaiter().GetResult(); }
-
- public void OnCompleted(Action action)
- {
- _task.ConfigureAwait(false).GetAwaiter().OnCompleted(action);
- }
-
- public void UnsafeOnCompleted(Action action)
- {
- _task.ConfigureAwait(false).GetAwaiter().UnsafeOnCompleted(action);
- }
- }
-}
diff --git a/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj b/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj
index 66f0da7b4d6a6c..a89cd7202c08e0 100644
--- a/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj
+++ b/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj
@@ -167,8 +167,6 @@
Link="Common\Interop\Unix\Interop.GetEUid.cs" />
-
diff --git a/src/libraries/System.Security.Cryptography.Primitives/src/System.Security.Cryptography.Primitives.csproj b/src/libraries/System.Security.Cryptography.Primitives/src/System.Security.Cryptography.Primitives.csproj
index 681bb084de8acf..e75bb29692d4fe 100644
--- a/src/libraries/System.Security.Cryptography.Primitives/src/System.Security.Cryptography.Primitives.csproj
+++ b/src/libraries/System.Security.Cryptography.Primitives/src/System.Security.Cryptography.Primitives.csproj
@@ -25,8 +25,6 @@
-
ReadAsyncInternal(byte[] buffer, int offset, int count,
// async requests outstanding, we will block the application's main
// thread if it does a second IO request until the first one completes.
- SemaphoreSlim semaphore = AsyncActiveSemaphore;
- await semaphore.WaitAsync(cancellationToken).ForceAsync();
+ await AsyncActiveSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
try
{
return await ReadAsyncCore(buffer, offset, count, cancellationToken, useAsync: true).ConfigureAwait(false);
}
finally
{
- semaphore.Release();
+ _lazyAsyncActiveSemaphore.Release();
}
}
@@ -495,15 +495,14 @@ private async Task WriteAsyncInternal(byte[] buffer, int offset, int count, Canc
// async requests outstanding, we will block the application's main
// thread if it does a second IO request until the first one completes.
- SemaphoreSlim semaphore = AsyncActiveSemaphore;
- await semaphore.WaitAsync(cancellationToken).ForceAsync();
+ await AsyncActiveSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
try
{
await WriteAsyncCore(buffer, offset, count, cancellationToken, useAsync: true).ConfigureAwait(false);
}
finally
{
- semaphore.Release();
+ _lazyAsyncActiveSemaphore.Release();
}
}
@@ -748,6 +747,7 @@ private void InitializeBuffer()
}
}
+ [MemberNotNull(nameof(_lazyAsyncActiveSemaphore))]
private SemaphoreSlim AsyncActiveSemaphore
{
get