ThreadStatic改性静态C# [英] ThreadStatic Modified with Static C#

查看:105
本文介绍了ThreadStatic改性静态C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码,我使用C#线程静态对象。

I have some code where I use a thread static object in C#.

[ThreadStatic]
private DataContext connection

我想知道,在这种情况下,如果任何改变我会得到,如果我把静态在线程静态上下文修改?

I was wondering, in this case, what if any change would I get if I put the static modifier on the thread static context?

[ThreadStatic]
private static DataContext connection

通过第一会有每个实例每线程上下文中的一个副本,每个线程其他只有一个副本?

With the first would there be one copy of the context per instance per thread, with the other only one copy per thread?

推荐答案

ThreadStaticAttribute 被设计为只对静态变量使用,的 MSDN指出。如果你把它用在一个实例变量,我怀疑它会做什么都不准确。

The ThreadStaticAttribute is only designed to be used on static variables, as MSDN points out. If you use it on an instance variable, I suspect it will do precisely nothing.

这篇关于ThreadStatic改性静态C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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