本文介绍了是否改变一个线程池线程的文化影响它时,它被返回到池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我设置了的CurrentCulture 线程池线程,当线程执行完毕,并得到返回到线程池,会发生什么?是否得到了的CurrentCulture 重置为默认值(无论这可能意味着),还是会保留我已经将它设置的文化?

If I set the CurrentCulture of a thread pool thread, what happens when the thread finishes execution and gets returned back to the thread pool? Does it get its CurrentCulture reset back to the default (whatever that may mean), or will it retain the culture I have set on it?

我希望框架线程重置为默认状态,以防止这种情况,但无法找到这种效果的任何文件。我发现的最接近是从MSDN文档的:

I'm hoping that the framework resets the thread to a default state to guard against this, but cannot find any documentation to this effect. The closest I have found is from the MSDN docs for ThreadPool:

当线程池中重用线程,
它不会清除线程
本地存储或在那些字段中的数据
标有ThreadStaticAttribute
属性。因此,即
由一个
法放置在线程局部存储器的数据可以暴露于由同一
线程池线程执行的任何其他

这似乎表明,该线程的不可以返回时将其重置。

This seems to indicate that the thread is not reset when it is returned.

我已经尝试了一些示例代码,试图测试,它的确实的似乎是文化复位,但我不相信我,因为我认为正确测试此行为我只使用线程池的线程的一小部分,所以不能肯定我测试一个线程,已经有它的文化集。

I have tried some sample code to try to test this, and it does seem that the culture is reset, but I am not convinced that I am testing this behaviour correctly as I think I am only using a small subset of the ThreadPool's threads, and so cannot be sure I'm testing a thread that has already had it's culture set.

推荐答案

我不会依靠线程池的曾经重新明确,因为你引用的文字信息。

I would not rely on the ThreadPool ever resetting information, specifically because of the text you quoted.

如果你是担心变线程池的文化,我会确保当你的线程任务已完成重新设置。这是一个再简单不过的任务。

If you are worried about "changing" the thread pool's culture, I would make sure to reset it when your threaded task is complete. This is a simple enough task.

我不认为目前的线程池做到这一点,但即使它的没有,它不会是安全的假定的.NET 4 + ThreadPool的实施将不会改变。

I do not believe the current threadpool does this, but even if it did, it would not be safe to assume that .NET 4+'s ThreadPool implementation will not change.

这篇关于是否改变一个线程池线程的文化影响它时,它被返回到池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 19:45