-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
Pri1deployment/techdoc-bugfeedback is about something that is out of date, unclear, confusing, or broken in the articlefeedback is about something that is out of date, unclear, confusing, or broken in the articleeng-triageduwp/prodwinui/tech
Description
In each of the C# examples, "ComputeNextMove()" returns a Task, but is not awaited. This is bad practice, and will result in lost exceptions and other negative side effects. Both examples are also exactly the same.
Here's a corrected C# code sample:
public class AsyncExample
{
private async void NextMove_Click(object sender, RoutedEventArgs e)
{
// The await causes the handler to return immediately.
await Task.Run(async () => await ComputeNextMove());
// Or even better, just: // await ComputeNextMove();
// Now update the UI with the results.
// ...
}
private async Task ComputeNextMove()
{
// Perform background work here.
// Don't directly access UI elements from this method.
}
}
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 5ed3306f-fb9a-0be1-b372-4a073bb3e57c
- Version Independent ID: fddfcca6-819d-e48a-9ab2-d12ab56ba796
- Content: Keep the UI thread responsive - Windows UWP applications
- Content Source: windows-apps-src/debug-test-perf/keep-the-ui-thread-responsive.md
- Product: uwp
- Technology: deployment
- GitHub Login: @eliotcowley
- Microsoft Alias: elcowle
Metadata
Metadata
Assignees
Labels
Pri1deployment/techdoc-bugfeedback is about something that is out of date, unclear, confusing, or broken in the articlefeedback is about something that is out of date, unclear, confusing, or broken in the articleeng-triageduwp/prodwinui/tech