Skip to content

fix(controls): Resolve ContentDialog ShowAsync task hanging issue#1615

Closed
apachezy wants to merge 2 commits intolepoco:mainfrom
apachezy:fix/contentdialog-showasync-tcs
Closed

fix(controls): Resolve ContentDialog ShowAsync task hanging issue#1615
apachezy wants to merge 2 commits intolepoco:mainfrom
apachezy:fix/contentdialog-showasync-tcs

Conversation

@apachezy
Copy link
Copy Markdown
Contributor

@apachezy apachezy commented Dec 20, 2025

Pull request type

Please check the type of change your PR introduces:

  • Update
  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes

What is the current behavior?

  • Opening a new ContentDialog before the previous one is closed causes task hanging—the ShowAsync method never returns.
    Typical scenario: Navigation between dialogs.

  • The DialogHost property is publicly writable; if modified while a dialog is displayed, it leads to inconsistent state.

Example of a problem:

ShowAsync-NoResult.mp4

Issue Number: N/A

What is the new behavior?

After the issue was fixed:

ShowAsync-Fixed.mp4

Other information

- Fixed dialog task hanging by handling Unloaded event to complete pending async operations when dialog is removed.

- Added `_capturedDialogHost` field to cache DialogHost value at opening, preventing race conditions from external modifications during display.

- Documented that DialogHost must be set before calling ShowAsync.
@github-actions github-actions Bot added controls Changes to the appearance or logic of custom controls. PR Pull request dotnet release labels Dec 20, 2025
@apachezy
Copy link
Copy Markdown
Contributor Author

To avoid conflicts with other PRs, I have merged the changes and will close this one.

@apachezy apachezy closed this Dec 21, 2025
@apachezy apachezy reopened this Dec 21, 2025
@apachezy apachezy closed this Dec 21, 2025
@apachezy apachezy deleted the fix/contentdialog-showasync-tcs branch December 27, 2025 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

controls Changes to the appearance or logic of custom controls. dotnet PR Pull request release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Critical] ContentDialog causes memory leaks when ShowAsync task hangs

1 participant