Skip to content

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

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

Open
vsfeedback opened this issue Jan 19, 2019 · 4 comments
Assignees
Labels
Bug Product bug (most likely)
Milestone

Comments

@vsfeedback
Copy link

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)

@rladuca rladuca added the Bug Product bug (most likely) label Jan 19, 2019
@rladuca rladuca added this to the Future milestone Jan 19, 2019
@lindexi
Copy link
Member

lindexi commented Jan 21, 2019

Windows systems do not tell to the dialog see: The Old New Thing: Practical Development Throughout the Evolution of Windows

@lindexi
Copy link
Member

lindexi commented Jan 21, 2019

When we use three windows to show and set the owner nested, the third window can not receive the message from the first window.

The demo:

The A window has a button that will show the B window when clicked.

    private void Button_OnClick(object sender, RoutedEventArgs e)
    {
        var b = new B();
        b.Owner = this;
        b.Show();
    }

The B window also has a button that will show the C window when clicked.

    private void Button_OnClick(object sender, RoutedEventArgs e)
    {
        var c = new C();
        c.Owner = this;
        c.Show();
    }

You can run the code and show the A B C window and then you will see the C window do not minimize when the A window minimize.

@GeneralWar
Copy link

I found the same problem, so it is really a bug and has not been solved?

@lindexi
Copy link
Member

lindexi commented Feb 14, 2025

@GeneralWar Yes, it is the known isssues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Product bug (most likely)
Projects
None yet
Development

No branches or pull requests

5 participants