问题描述
标题是关于它的.带有一些用于 IPC 的 WCF 内容的 WPF 应用程序.我调用 Application.Current.Shutdown()
并且应用程序继续愉快地运行.我认为 Shutdown
应该是不可阻挡的.
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?
推荐答案
当我在主线程以外的任何线程中调用 Application.Current.Shutdown
时,您会得到一个异常,所以我假设你已经正确使用了调度员摆弄".
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();
这篇关于Application.Current.Shutdown() 没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!