开发者

Can I (safely) use the ThreadStatic attribute in ADO.NET Data Services?

I want to store per-thread data in an ADO.NET Data Service. Is it safe to use the ThreadStatic attribute on my thread-specific static variable, or will I run into problems? My concern is that my ThreadStatic variable(s) won't be garbage collected after the request is completed and the thread dies.

If there's a better way to do what I'm trying to do, please let me know. This just seems like the simplest sol开发者_StackOverflow中文版ution.

Any information would be very helpful, thanks!


I've found that the DataService object that's created for each request is on a thread marked with IsThreadPoolThread = true, so using the [ThreadStatic] attribute is not appropriate in this case, as information from previous requests could be available by later ones (not desirable).


Any variables which are tagged with ThreadStatic will have the lifetime at least as long as the thread on which they are created. After that Thread terminates they are subject to garbage collection like any other value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜