开发者

C# multithreaded windows service, private or [ThreadStatic]

I'm in the process of converting a console application I wrote from a single windows service to a windows service that supports multithreading. However, this is my first go around with multithreads.

I was wondering if I should make every class private static instead of public static and for anything that has to remain public, attach the [ThreadStatic] attribute.

Bas开发者_如何学JAVAically the code does a lot of string work from HTML Crawling and then places select data in a mysql database.


The answer to your first question is no; adapting your code to support multiple threads does not (necessarily) mean you need to change member or type accessibility.

As to your second question, use the ThreadStatic on fields (not types) if you need each thread to have its own independent static field (otherwise all threads will share the same static field).


I don't know, it feels dirty. I would rather create some kind of management class to manage all objects and pass the values between them.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜