System.Threading.Tasks.Task.Yield Method

Creates an awaitable task that asynchronously yields back to the current context when awaited.

Syntax

public static System.Runtime.CompilerServices.YieldAwaitable Yield ()

Returns

A context that, when awaited, will asynchronously transition back into the current context at the time of the await. If the current System.Threading.SynchronizationContext is non-null, it is treated as the current context. Otherwise, the task scheduler that is associated with the currently executing task is treated as the current context.

Remarks

You can use await Task.Yield(); in an asynchronous method to force the method to complete asynchronously. If there is a current synchronization context (System.Threading.SynchronizationContext object), this will post the remainder of the method’s execution back to that context. However, the context will decide how to prioritize this work relative to other work that may be pending. The synchronization context that is present on a UI thread in most UI environments will often prioritize work posted to the context higher than input and rendering work. For this reason, do not rely on await Task.Yield(); to keep a UI responsive. For more information, see the entry tp://blogs.msdn.com/b/pfxteam/archive/2008/07/23/8768673.aspx in the Parallel Programming with .NET blog.

Requirements

Namespace: System.Threading.Tasks
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 4.0.0.0