杀那个打开的应用程序的所有线程 [英] Killing all threads that opened by application

查看:168
本文介绍了杀那个打开的应用程序的所有线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对C#和J#一些非常大的应用程序混合。

I have some really big application mixture of c# and j#.

有时候,当我关闭它,有没有被关闭了一些线程,它们被挂在任务管理器,这是不可能从那里杀了他们。

Sometimes when I close it, there are some threads that are not closed and they are hanging in the task manager and it is impossible to kill them from there.

我真有问题,找到所有这些线程,并把它们添加到结束活动。

I have really problem to find all those threads and add them to the closing event .

有一些方法猛烈杀死在结束活动的应用程序中打开的所有线程?...

Is there some way violently kill all threads that were opened by application in the closing event ?...

感谢。

有可能一些工具,可以告诉我什么线程被打开,而我关闭应用程序,谁openned他们?

Is there maybe some Tool that can tell me what threads are opened while i close the application and who openned them ?

推荐答案

本的不应该发生的,如果是,你试图解决这一问题的错误的方式。

This shouldn't be happening, and if it is, you're trying to address it the wrong way.

当你的应用程序退出时,.NET Framework将自动杀死任何线程的<一个href="http://msdn.microsoft.com/en-us/library/system.threading.thread.isbackground.aspx"><$c$c>IsBackground物业设置为真。指定你的每个工作线程的后台线程,你不会有这样的问题了。趁着的<一个href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx"><$c$c>BackgroundWorker类和<一href="http://msdn.microsoft.com/en-us/library/system.threading.threadpool.aspx"><$c$c>ThreadPool类,它自动创建的后台线程,是一个更好的选择。

When your application exits, the .NET Framework will automatically kill any threads whose IsBackground property is set to "True". Designate each of your worker threads as background threads, and you won't have this problem anymore. Taking advantage of the BackgroundWorker class and the ThreadPool class, which automatically create background threads, is a much better option.

否则,您需要显式地清理你的前台线程。一个设计合理的应用程序将尽自己的簿记并确保其所有线程都退出方法之前已关闭一个确定性的,结构化的方式。这是你应该做的反正的,如果你的线程需要正常终止。

Otherwise, you need to clean up your foreground threads explicitly. A properly designed application will do its own bookkeeping and have a deterministic, structured way of ensuring that all its threads have been closed before exiting the Main method. This is what you should be doing anyway if your threads require a graceful termination.

杀的过程是一个非常糟糕的主意,因为是让你的线程在应用程序运行大约慎之又慎。

Killing the process is a very bad idea, as is letting your threads run about willy-nilly in your application.

这篇关于杀那个打开的应用程序的所有线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆