Application.Current.Shutdown() doesn't

Thomas picture Thomas · Dec 8, 2009 · Viewed 11.8k times · Source

Title's about it. WPF app with some WCF stuff for IPC. I call Application.Current.Shutdown() and the app continues on happily. I thought Shutdown was supposed to be unstoppable.

Perhaps because it's being called from a background thread? Do I need to do some dispatcher fiddling?

Answer

MoominTroll picture MoominTroll · Dec 8, 2009

You get an exception when I call Application.Current.Shutdown in any thread other than the main one, so I'd assume you where using "dispatcher fiddling" properly already.

In any case, this compiles and quits an application, so if the dispatcher bit doesn't look like what you have you could sling it in:

ThreadStart ts = delegate()
    {
        Dispatcher.BeginInvoke((Action)delegate()
        {
            Application.Current.Shutdown();
        });
     };
 Thread t = new Thread(ts);
 t.Start();