H
Harold Howe
I would like to display a modal dialog after Application.Run returns. In
this particular case, it is a dialog to inform the user that some
cleanup code suffered catastrophic failure.
I have discovered that forms cannot be shown modally once Run returns.
Is there a way to alter this behavior? What is the best way to show a
dialog when the app is in the process of shutdown? Am I doing something
wrong?
Here is a short example of the problem.
using System;
using System.Windows.Forms;
namespace Test
{
class Test
{
static void Main()
{
Form f = new Form();
f.Text = "Main form";
Application.Run(f);
f = new Form();
f.Text = "Goodbye form.";
f.ShowDialog();
}
}
}
The goodbye dialog appears briefly on the screen, and then disappears.
I don't understand why the framework doesn't allow this. It is possible
to show forms modally before Run, but not after.
The workarounds I have found are to replace f.ShowDialog with
Application.Run(f); // just call Run again
f.Show()
while(f.Visible)
Application.DoEvents();
I would prefer to not have to resort to either of these, but may not
have a choice. Any suggestion?
H^2
this particular case, it is a dialog to inform the user that some
cleanup code suffered catastrophic failure.
I have discovered that forms cannot be shown modally once Run returns.
Is there a way to alter this behavior? What is the best way to show a
dialog when the app is in the process of shutdown? Am I doing something
wrong?
Here is a short example of the problem.
using System;
using System.Windows.Forms;
namespace Test
{
class Test
{
static void Main()
{
Form f = new Form();
f.Text = "Main form";
Application.Run(f);
f = new Form();
f.Text = "Goodbye form.";
f.ShowDialog();
}
}
}
The goodbye dialog appears briefly on the screen, and then disappears.
I don't understand why the framework doesn't allow this. It is possible
to show forms modally before Run, but not after.
The workarounds I have found are to replace f.ShowDialog with
Application.Run(f); // just call Run again
f.Show()
while(f.Visible)
Application.DoEvents();
I would prefer to not have to resort to either of these, but may not
have a choice. Any suggestion?
H^2