-
Notifications
You must be signed in to change notification settings - Fork 6k
Document breaking change for BackgroundService ExecuteAsync behavior in .NET 10 #49121
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
Conversation
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
docs/core/compatibility/extensions/10.0/backgroundservice-executeasync-task.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/extensions/10.0/backgroundservice-executeasync-task.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/extensions/10.0/backgroundservice-executeasync-task.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/extensions/10.0/backgroundservice-executeasync-task.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/extensions/10.0/backgroundservice-executeasync-task.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/extensions/10.0/backgroundservice-executeasync-task.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/extensions/10.0/backgroundservice-executeasync-task.md
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR documents a breaking behavioral change in .NET 10 where BackgroundService.ExecuteAsync
now runs entirely on a background thread instead of having its synchronous portion (before the first await
) run on the main thread during service startup. The change was made because the previous behavior was a common pitfall that didn't meet user expectations.
Key changes:
- Added comprehensive breaking change documentation with code examples and migration guidance
- Updated table of contents and index files to include the new documentation
- Provided four specific approaches for developers who need the previous synchronous startup behavior
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
docs/core/compatibility/extensions/10.0/backgroundservice-executeasync-task.md |
New breaking change document explaining the behavior change and migration options |
docs/core/compatibility/toc.yml |
Added TOC entry for the new breaking change document |
docs/core/compatibility/10.0.md |
Added index entry for the breaking change in the Extensions section |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM.
Let's
Fixes #495675
This PR documents a breaking behavioral change in .NET 10 where
BackgroundService.ExecuteAsync
now runs entirely on a background thread instead of running the synchronous portion (before the firstawait
) on the main thread during service startup.What Changed
Previously, the synchronous portion of
ExecuteAsync
would run on the main thread and block other services from starting. Only code after the firstawait
would run on a background thread. This behavior was intended to allow developers to partition synchronous and asynchronous work, but most implementers didn't understand or expect this nuance.Starting in .NET 10 Preview 1, all of
ExecuteAsync
runs on a background thread, and no part of it blocks other services from starting.Documentation Added
docs/core/compatibility/extensions/10.0/backgroundservice-executeasync-task.md
StartAsync
and callbase.StartAsync()
IHostedLifecycleService
for more specific startup timingIHostedService
directly instead of usingBackgroundService
docs/core/compatibility/toc.yml
docs/core/compatibility/10.0.md
References
Original prompt
Fixes #48878
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Internal previews