FLCL
FLCL

Reputation: 2514

Unable to ShowDialog repeatedly

In constructor of my App class am showing window as dialog repeatedly while it returns true:

public App()
{       
    for (;;)
    {
        ...
        var factory = new ControlsFactory<int>();
        var window = factory.CreateWindow(model);
        var result = window.ShowDialog();
        if (!(result ?? false)) return;                
    }
}

It shows at first iteration successfully and returns true(I have a button with click handler in it, where I set DialogResult = true;), but next time it just returns false immediately and loop gets broken. Is there any way to show window as dialog consequentially and infinitely?

Upvotes: 2

Views: 104

Answers (1)

user585968
user585968

Reputation:

You may need to set Application.Current.ShutdownMode to ShutdownMode.OnExplicitShutdown.

MSDN:

ShutdownMode.OnExplicitShutdown

An application shuts down only when Shutdown is called.

This is because, showing a modal dialog (when it is the only window present) will by default cause an application quit message to be posted, thus causing any future windows to immediately close before they are shown visually.

Upvotes: 1

Related Questions