为什么Thread类不支持IDisposable? [英] Why does Thread class not support IDisposable?

查看:134
本文介绍了为什么Thread类不支持IDisposable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Thread类不支持IDisposable?它创造了相当多的问题。也就是说,它可以耗尽资源而你没有对它进行控制。

Why does Thread class not support IDisposable? It''s creating quite
some problem. Namely, it can exhaust the resource and you have not
control over it.

推荐答案

12月7日,2: 19 pm,Creativ< GongXinr ... @ gmail.comwrote:
On Dec 7, 2:19 pm, Creativ <GongXinr...@gmail.comwrote:

为什么Thread类不支持IDisposable?
Why does Thread class not support IDisposable?



为什么要这样? Thread.Dispose实际上会做什么?

Why should it? What would Thread.Dispose actually do?


这会产生一些问题。也就是说,它可以耗尽资源,而你b
无法控制它。
It''s creating quite some problem. Namely, it can exhaust the resource and you
have not control over it.



我已经做了相当多的线程并且从未陷入过这种情况

我想要处理一个线程。现在用

优雅方式终止一个线程是另一回事 - 但这取决于线程之间的

协作。如果你需要硬重置一个

线程,Abort是你的朋友 - 但你应该真的这样做,如果

你正在拆除这个过程(或者至少是AppDomain),因为它

让事物处于不确定状态。


Jon

I''ve done a fair amount of threading and never got into a situation
where I want to dispose of a thread. Now terminating a thread in a
graceful manner is a different matter - but that''s up to the
collaboration between the threads. If you need to "hard" reset a
thread, Abort is your friend - but you should only really do that if
you''re tearing down the process (or at least the AppDomain) as it
leaves things in an indeterminate state.

Jon


我能想到的情景是你创建一个线程来运行一些任务。

经过一些运行后,会创建相当多的线程。在做了很长一段时间的
之后,你会遇到创建Thread并运行它的问题

因为CloseHandle会在Finalizer中被调用。

The scenario I can think of is you create a thread to run some task.
After some runs, quite some threads will be created. After doing that
for a long time, you will have problem in creating Thread and run it
since the CloseHandle will be called in the Finalizer.


12月7日下午2:37,Creativ< GongXinr ... @ gmail.comwrote:
On Dec 7, 2:37 pm, Creativ <GongXinr...@gmail.comwrote:

我能想到的场景是你创建一个线程来运行一些任务。

经过一些运行后,会创建相当多的线程。在长时间执行

之后,您将遇到创建Thread并运行它的问题

,因为将在Finalizer中调用CloseHandle。
The scenario I can think of is you create a thread to run some task.
After some runs, quite some threads will be created. After doing that
for a long time, you will have problem in creating Thread and run it
since the CloseHandle will be called in the Finalizer.



如果你有那么多实际线程,那么你有更大的问题

无论如何。你真的遇到过这个问题吗?你见过

其他人遇到这个问题吗?


Jon

If you''ve got that many actual threads, you''ve got bigger problems
anyway. Have you actually run into this as a problem? Have you seen
anyone else running into this as a problem?

Jon


这篇关于为什么Thread类不支持IDisposable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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