Easly Easly - 7 months ago 28
C# Question

Show a Window while application is closing

I've a very heavy application that takes some time to close itself (it also depends on the pc where it is running.. but this is not the matter right now)

I would like to show a custom window with a message during this closing time, but as soon as i call the "Shutdown" method every window disappears (except made for the MessageBox).

This is the code i'm trying to use to achieve my objective

void MainWindow_Closing(object sender, CancelEventArgs e)
{
Task.Factory.StartNew(() =>
{
var closingWaitTest = "application closing, please wait;
Application.Current.Dispatcher.Invoke(() =>
{
var closingSplash = new ClosingSplashWindow(closingWaitTest);
closingSplash.Show();
});

MessageBox.Show(closingWaitTest);
});

Application.Current.Shutdown();
}


I Added a messageBox just to check, and it actually works. I mean, the MessageBox stays open until the application process is alive (i check that from the windows TaskManager) while my Window is instantly closed.

Hope someone can give some advice about this,
thanks in advance (:

EDIT -

So, the main problem is that as soon as i call the Application.Current.Shutdown my splash window instantly closes, while the application process is still up and running for some time (disposing all my things before calling shutdown actually reduced this time a bit).

The point is that i would like to show a window for the entirety of time that the process is still up; given the fact that a MessageBox behaves exactly like that, my question is:
Is there a way to make my ClosingSplashWindow behave like a MessageBox and stay visible until the application process is really dead?

Answer Source

In the end I solved the problem creating another application that shows a window while the main application process is still up and running.

I know it is not the best way to do it, but i was not able to do it in any other way..

Thank for the support! :)