dotnet / dotnet/wpf

WPF ShowDialog() never returns when a dialog's owner is closed and that owner is another dialog

Open
#277 4 comments 3 reactions 1 assignee Claimed by @dipeshmsft View on GitHub
Bug
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

I'm attaching a project that succinctly shows the bug, but here's the idea:

1. Create a WPF app with a main window.
2. Click a button that does two things:
2a. Immediately shows another window as a dialog (using ShowDialog())
2b. After a short delay, shows a third window as a dialog whose owner is the second window (the first dialog)
3. In the first dialog's Loaded handler, the dialog closes itself after a short delay.

What should happen:
Both dialogs close and both dialogs' ShowDialog() methods return.

What actually happens:
Both dialogs close but neither dialog's ShowDialog() method returns.

In the attached sample, a counter is used to keep track of how many dialogs are currently being shown, based on the number of ShowDialog() calls. Clicking the button multiple times keeps increasing the number of dialogs open (ShowDialog() calls). Commenting out the indicated line in MainWindow.xaml.cs works around the bug.

Motivating example:
In my app the first thing the user does is create a "workspace". Creating a workspace involves a number of steps and we show a progress dialog while those steps are being performed. That progress dialog is dialog #1 from the sample. Meanwhile, the app also checks for updates in the background during startup. If an update is found, a separate dialog is shown telling the user about the update. That is dialog #2. If the user happens to tell the app to create a workspace and, while creating the workspace, an update is found, this bug is hit.

_This issue has been moved from https://developercommunity.visualstudio.com/content/problem/51151/wpf-showdialog-never-returns-when-a-dialogs-owner.html
VSTS ticketId: 428554_
_These are the original issue comments:_

Henning Dampel on 5/24/2018, 02:15 AM (239 days ago):

ShowDialog() also never returns if the dialog's owner is a normal window that closes.

_These are the original issue solutions:_
(no solutions)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.