Multi-threading libraries for .NET

后端 未结 10 1949
长发绾君心
长发绾君心 2021-02-14 08:39

I used multiple threads in a few programs, but still don\'t feel very comfortable about it.

What multi-threading libraries for C#/.NET are out there and which advantages

相关标签:
10条回答
  • 2021-02-14 09:05

    I like this one http://www.codeplex.com/smartthreadpool

    0 讨论(0)
  • 2021-02-14 09:05

    For me the builtin classes of the Framework are more than enough. The Threadpool is odd and lame, but you can write your own easily.

    I often used the BackgroundWorker class for Frontends, cause it makes life much easier - invoking is done automatically for the eventhandlers.

    I regularly start of threads manually and safe them in an dictionary with a ManualResetEvent to be able to examine who of them has ended already. I use the WaitHandle.WaitAll() Method for this. Problem there is, that WaitHandle.WaitAll does not acceppt Arrays with more than 64 WaitHandles at once.

    0 讨论(0)
  • 2021-02-14 09:11

    You should take a look at the Concurrency & Coordination Runtime. The CCR can be a little daunting at first as it requires a slightly different mind set. This video has a fairly good job of explanation of its workings...

    In my opinion this would be the way to go, and I also hear that it will use the same scheduler as the TPL.

    0 讨论(0)
  • 2021-02-14 09:12

    Please keep in mind that you really should be closing threads (or allowing the threadpool to dispose) when you no longer need them, unless you will need them again soon. The reason I say this is that each thread requires stack memory (usually 1mb), so when you have applications sitting on threads but not using them, you are wasting memory.

    For exmaple, Outlook on my machine right now has 20 threads open and is using 0% CPU. That is simply a waste of (a least) 20mb of memory. Word is also using another 10 threads with 0% CPU. 30mb may not seem like much, but what if every application was wasting 10-20 threads?

    Again, if you need access to a threadpool on a regular basis then you don't need to close it (creating/destroying threads has an overhead).

    0 讨论(0)
  • 2021-02-14 09:13

    Check out the Power Threading library.

    0 讨论(0)
  • 2021-02-14 09:18

    You might want to look at the series of articles about threading patterns. Right now it has sample codes for implementing a WorkerThread and a ThreadedQueue.

    http://devpinoy.org/blogs/jakelite/archive/tags/Threading+Patterns/default.aspx

    0 讨论(0)
提交回复
热议问题