Yield Method

Task.Yield Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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

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

public static YieldAwaitable Yield()

Return Value

Type: System.Runtime.CompilerServices.YieldAwaitable
A context that, when awaited, will asynchronously transition back into the current context at the time of the await. If the current 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.

You can use await Task.Yield(); in an asynchronous method to force the method to complete asynchronously. If there is a current synchronization context (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.

Windows Phone OS

Supported in: 8.1, 8.0

Show:
© 2017 Microsoft