Skip to content

Task completion and exception handling#53005

Merged
BillWagner merged 7 commits intodotnet:mainfrom
BillWagner:async-aweigh-5
Apr 27, 2026
Merged

Task completion and exception handling#53005
BillWagner merged 7 commits intodotnet:mainfrom
BillWagner:async-aweigh-5

Conversation

@BillWagner
Copy link
Copy Markdown
Member

@BillWagner BillWagner commented Apr 14, 2026

  1. Create task-exception-handling.md — from "Task exception handling in .NET 4.5." Covers GetAwaiter().GetResult() vs .Result exception propagation, AggregateException unwrapping, unobserved task exceptions, TaskScheduler.UnobservedTaskException. Update: modern .NET default behavior (unobserved exceptions no longer crash the process).
  2. Create complete-your-tasks.md — from "Don't forget to complete your tasks." Covers: always complete TaskCompletionSource on all paths, common bugs (forgetting SetException in catch, dropping TaskCompletionSource references during reset).
  3. Incorporate FAQ content about Task.Result vs GetAwaiter().GetResult().
  4. Add both to TOC.

Internal previews

📄 File 🔗 Preview link
docs/navigate/advanced-programming/toc.yml docs/navigate/advanced-programming/toc
docs/standard/asynchronous-programming-patterns/complete-your-tasks.md Complete your tasks
docs/standard/asynchronous-programming-patterns/task-exception-handling.md Task exception handling

1. Create `task-exception-handling.md` — from "Task exception handling in .NET 4.5." Covers `GetAwaiter().GetResult()` vs `.Result` exception propagation, `AggregateException` unwrapping, unobserved task exceptions, `TaskScheduler.UnobservedTaskException`. **Update:** modern .NET default behavior (unobserved exceptions no longer crash the process).
1. Create `complete-your-tasks.md` — from "Don't forget to complete your tasks." Covers: always complete `TaskCompletionSource` on all paths, common bugs (forgetting `SetException` in catch, dropping `TaskCompletionSource` references during reset).
1. Incorporate FAQ content about `Task.Result` vs `GetAwaiter().GetResult()`.
1. Add both to TOC.
@dotnetrepoman dotnetrepoman Bot added this to the April 2026 milestone Apr 14, 2026
@BillWagner BillWagner marked this pull request as ready for review April 15, 2026 11:46
@BillWagner BillWagner requested a review from a team as a code owner April 15, 2026 11:46
Copilot AI review requested due to automatic review settings April 15, 2026 11:46
@BillWagner BillWagner marked this pull request as draft April 15, 2026 11:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds two new TAP-focused documentation articles to the async programming patterns section, with runnable C# and Visual Basic snippets, and exposes the new content in the navigation TOC.

Changes:

  • Adds Task exception handling guidance covering blocking APIs (Result/Wait() vs GetAwaiter().GetResult()), AggregateException, and unobserved task exceptions.
  • Adds Complete your tasks guidance focused on correctly completing TaskCompletionSource across all code paths, handling races, and safe reset patterns.
  • Adds both new articles to the advanced programming TOC.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
docs/standard/asynchronous-programming-patterns/task-exception-handling.md New article describing exception propagation and unobserved task exception behavior, with snippet includes.
docs/standard/asynchronous-programming-patterns/snippets/task-exception-handling/csharp/TaskExceptionHandling.csproj New C# snippet project for the task exception handling article.
docs/standard/asynchronous-programming-patterns/snippets/task-exception-handling/csharp/Program.cs C# examples for single/multiple exception propagation and UnobservedTaskException.
docs/standard/asynchronous-programming-patterns/snippets/task-exception-handling/vb/TaskExceptionHandling.vbproj New VB snippet project for the task exception handling article.
docs/standard/asynchronous-programming-patterns/snippets/task-exception-handling/vb/Program.vb VB examples for single/multiple exception propagation and UnobservedTaskException.
docs/standard/asynchronous-programming-patterns/complete-your-tasks.md New article describing safe TaskCompletionSource completion patterns and reset pitfalls, with snippet includes.
docs/standard/asynchronous-programming-patterns/snippets/complete-your-tasks/csharp/CompleteYourTasks.csproj New C# snippet project for the complete-your-tasks article.
docs/standard/asynchronous-programming-patterns/snippets/complete-your-tasks/csharp/Program.cs C# examples showing common TaskCompletionSource completion bugs and fixes.
docs/standard/asynchronous-programming-patterns/snippets/complete-your-tasks/vb/CompleteYourTasks.vbproj New VB snippet project for the complete-your-tasks article.
docs/standard/asynchronous-programming-patterns/snippets/complete-your-tasks/vb/Program.vb VB examples showing common TaskCompletionSource completion bugs and fixes.
docs/navigate/advanced-programming/toc.yml Adds TOC entries for the two new articles.

Restructure, add links, and add xrefs.
@BillWagner BillWagner marked this pull request as ready for review April 15, 2026 17:08
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Comment thread docs/standard/asynchronous-programming-patterns/complete-your-tasks.md Outdated
Comment thread docs/standard/asynchronous-programming-patterns/task-exception-handling.md Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@BillWagner BillWagner requested a review from adegeo April 15, 2026 17:18
@BillWagner
Copy link
Copy Markdown
Member Author

@adegeo This is ready for final review.

Copy link
Copy Markdown
Contributor

@adegeo adegeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. I pointed out a possible improvement. I don't know if it makes sense since this is "exception handling" but we area suggesting a code path that could potentially deadlock based on the environment it's running in.

Comment thread docs/standard/asynchronous-programming-patterns/task-exception-handling.md Outdated
The desktop docset has recommendations on using GetAwaiter().GetResult() in Winforms apps.
@BillWagner BillWagner merged commit cf2c49c into dotnet:main Apr 27, 2026
9 checks passed
@BillWagner BillWagner deleted the async-aweigh-5 branch April 27, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants