Bug: Using a non-reentrant wait synchronization context causes app to hang on exit
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 665
- Forks
- 134
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 32
Description
Description
For more context see https://github.com/microsoft/CsWinRT/issues/2422. Basically, the issue is if I subclass DispatcherQueueSynchronizationContext to use a non-reentrant wait to avoid reentrancy issues in WindowsAppSDK, then the app hangs on exit. There is an easy workaround which is to revert to the standard wait on FrameworkShutdownStarting. However, it would be nice if this wasn't needed. I'm posting here now in case this reqires any .net runtime updates before v11 is released.
Steps To Reproduce
Use this code in app startup where CustomDispatcherQueueSynchronizationContext is given in https://github.com/microsoft/CsWinRT/issues/2422 (and remove the workaround when shutting down).
Application.Start((p) => {
var context = new CustomDispatcherQueueSynchronizationContext(DispatcherQueue.GetForCurrentThread());
SynchronizationContext.SetSynchronizationContext(context);
_ = new App();
});
Expected Behavior
No hang on exit
Version Info
Last tested on CsWinRT 2.2, WindowsAppSDK 2.0
Additional Context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CustomDispatcherQueueSynchronizationContext example in CsWinRT issue #2422 and the Application.Start setup shown here. Reproduce the hang using the non-reentrant wait without the FrameworkShutdownStarting workaround, then trace shutdown behavior. Done means the app exits without hanging while retaining the non-reentrant wait.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 45/100