Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a basic example #583

Closed
wants to merge 8 commits into from
Closed
Changes from 2 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
18 changes: 17 additions & 1 deletion xml/System.Threading.Tasks/Task.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5447,10 +5447,26 @@ Task t Status: RanToCompletion, Result: 42

## 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 (<xref: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 [Useful Abstractions Enabled with ContinueWith](http://blogs.msdn.com/b/pfxteam/archive/2008/07/23/8768673.aspx) in the Parallel Programming with .NET blog.

A good example of the usage would be a `Windows Forms` application where you would like to execute an action but at the same time release the thread so the UI would be accessible to user.
```cs
async void Form_Load(object s, object e)
{
await Task.Yield(); // unblock the UI before doing potentially lengthy operation
LoadLocalConfiguration();
yashints marked this conversation as resolved.
Show resolved Hide resolved
}
```

```vb
Private Async Sub Form_Load(ByVal s As Object, ByVal e As Object)
Await Task.Yield ' unblock the UI before doing potentially lengthy operation
LoadLocalConfiguration();
End Sub
```

]]></format>
</remarks>
</Docs>
</Member>
</Members>
</Type>
</Type>