Bob
Bob

Reputation: 381

shutdown wpf while messagebox open

I try to automatically shut down an wpf application at midnight with:

Dispatcher.BeginInvokeShutdown(DispatcherPriority.Normal);

This works very well in general, but when there is a message box opening waiting for user response, the application fails to shutdown. Is there a way to shut down the application regardless of the opening messagebox?

Upvotes: 0

Views: 1556

Answers (2)

Nikhil Agrawal
Nikhil Agrawal

Reputation: 48558

For WPF Applications use

Application.Current.Shutdown();

Upvotes: 1

Colin Smith
Colin Smith

Reputation: 12540

Maybe you can use Environment.Exit (immediately exits...very naughty to do on a GUI app) or find the MessageBox window and send them a close message, or hook the creation of any native MessageBox Dialogs (...i.e. track the Window handle, so you can then close them).

And a very very naughty way:

Process.GetCurrentProcess().Kill()

Upvotes: 1

Related Questions