Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我创建了一个运行多个后台线程的表单。我添加了另一个处理异常和错误(如果有)的类。当代码运行时,如果发生应该强制应用程序关闭的错误,我可以使用Application.Exit()吗?这也会杀死后台线程吗?
Application.Exit()
不,它不会。Application.Exit() 将简单地强制 Windows 消息泵发布退出消息,这将终止您的应用程序的主线程。但是,进程本身将继续运行,直到后台线程完成。
更新:正如评论者正确指出的那样,如果您的线程的 IsBackground 属性设置为 True,则通过 Application.Exit() 终止主线程将关闭该进程。
不,线程终止是合作的。