是否.NET线程池线程得到复位,当它返回到池中? [英] Does .NET ThreadPool thread get reset when it goes back to the pool?

查看:198
本文介绍了是否.NET线程池线程得到复位,当它返回到池中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当一个线程池中的线程完成,不会的东西,如姓名或线程本地数据得到恢复? 因此,当线程出来的水池旁时间,它就像全新的?

When a thread pool thread is done, does stuff like Name or thread local data get reset? So when the thread comes out of the pool next time, it's like brand new?

有没有对线程池线程这方面?

Is there an "official" documentation on this aspect of the ThreadPool threads?

推荐答案

不清晰的脉络时,它释放的本地存储,这是需要注意的最重要的方面。

It does NOT clear thread local storage when it's released, which is the most important aspect to note.

<一个href="http://msdn.microsoft.com/en-us/library/system.threading.threadpool.aspx">http://msdn.microsoft.com/en-us/library/system.threading.threadpool.aspx

当线程池中重新使用一个线程,它不清除数据   线程本地存储或者在标有领域   ThreadStaticAttribute属性。因此,数据被放置在   线程本地存储通过一种方法可以暴露于任何其它方法   是由相同的线程池线程执行。一种方法,   访问了标有ThreadStaticAttribute场   属性可能会遇到不同的数据,这取决于线程   池中的线程执行。

When the thread pool reuses a thread, it does not clear the data in thread local storage or in fields that are marked with the ThreadStaticAttribute attribute. Therefore, data that is placed in thread local storage by one method can be exposed to any other method that is executed by the same thread pool thread. A method that accesses a field that is marked with the ThreadStaticAttribute attribute could encounter different data depending on which thread pool thread executes it.

这是值得非常小心......

This is something to be very careful about...

这篇关于是否.NET线程池线程得到复位,当它返回到池中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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