Skip to content

Port wil::resume_foreground - #1574

Open
Yexuan Xiao (YexuanXiao) wants to merge 4 commits into
microsoft:masterfrom
YexuanXiao:resume_foreground-upstream
Open

Yexuan Xiao (YexuanXiao) wants to merge 4 commits into
microsoft:masterfrom
YexuanXiao:resume_foreground-upstream

Conversation

@YexuanXiao

@YexuanXiao Yexuan Xiao (YexuanXiao) commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

This PR ports wil::resume_background with a few small improvements:

  • Uses operator() instead of Schedule, support using lambdas to replace cumbersome struct definitions.
  • Uses the destructor of dispatcher_state_guard instead of try {} catch (...) { throw; } pattern, which help compiler generates cleaner code.

C++/WinRT 3.0 should fix this issue, as it could cause coroutines to run on the wrong thread or leak. Since almost no one checks the return value of co_await, this will hardly break existing code.

C++/WinRT already has special handling for WinUI (base_xaml_component_connector_winui.h), so unless there are plans to remove that code from C++/WinRT, support for Microsoft::UI::Dispatching::DispatcherQueue should not be rejected.

The tests are also port from wil, identical except for the namespace name.

@willdieh

Copy link
Copy Markdown

PLEASE accept this pull request - having to import WIL just to do resume_foreground is unfortunate. The advanced threading documentation for cpp/winrt still have the resume_foreground example for the more general use case of obtaining the UI thread and omit the WIL requirement. It took me a whole day to figure out that WIL was required (although it is discussed in the migration docs). Looks like this pull is ready to approve 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants