diff --git a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs index fb6f2197c06a..8118cfd2b5e9 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs @@ -191,13 +191,6 @@ private void NotifySynchronizationContextOfCompletion() /// public struct AsyncTaskMethodBuilder { - /// A cached VoidTaskResult task used for builders that complete synchronously. -#if PROJECTN - private static readonly Task s_cachedCompleted = AsyncTaskCache.CreateCacheableTask(default(VoidTaskResult)); -#else - private static readonly Task s_cachedCompleted = AsyncTaskMethodBuilder.s_defaultResultTask; -#endif - /// The generic builder object to which this non-generic instance delegates. private AsyncTaskMethodBuilder m_builder; // mutable struct: must not be readonly. Debugger depends on the exact name of this field. @@ -270,7 +263,7 @@ public Task Task /// /// The builder is not initialized. /// The task has already completed. - public void SetResult() => m_builder.SetResult(s_cachedCompleted); // Using s_cachedCompleted is faster than using s_defaultResultTask. + public void SetResult() => m_builder.SetResult(Task.s_cachedCompleted); // Using s_cachedCompleted is faster than using s_defaultResultTask via generic. /// /// Completes the in the diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs index 2c35214248ff..9d4fcffbbf0b 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs @@ -1497,8 +1497,10 @@ bool IAsyncResult.CompletedSynchronously /// public static TaskFactory Factory { get; } = new TaskFactory(); + // Is a Task{VoidTaskResult} so it can be shared with AsyncTaskMethodBuilder + internal static readonly Task s_cachedCompleted = new Task(false, default, (TaskCreationOptions)InternalTaskOptions.DoNotDispose, default); /// Gets a task that's already been completed successfully. - public static Task CompletedTask { get; } = new Task(false, (TaskCreationOptions)InternalTaskOptions.DoNotDispose, default); + public static Task CompletedTask => s_cachedCompleted; /// /// Provides an event that can be used to wait for completion.