C # Threading, GetAvailableThreads ()
I have a problem with threads,
I set it ThreadPool.SetMaxThreads(maxThreads, System.Environment.ProcessorCount)
to 10.
But when I check how many of them are available ThreadPool.GetAvailableThreads()
, it says there is (maxThreads - 1), so 9, but then keeps using 10 threads.
Any ideas why this is?
Thanks for the help.
In an ideal world, we would have 1 thread / physical core. This way we no longer have context switches, which are quite expensive operations. But as long as we have processors with hundreds of cores, this will not be practical.
In any case, as Mark suggested, you shouldn't mess with the ThreadPool parameters unless you REALLY know what you are doing. The implementation logic of the .Net ThreadPool implementation is pretty good and can handle most scenarios successfully.
source to share
Are you queuing up streams with something similar?
ThreadPool.QueueUserWorkItem(callback, obj)
and then do something like:
WaitHandle.WaitAll(WaitHandle)
I am assuming there is a problem with how you actually calculate the threads that work, but without a more specific explanation of what you are doing, this is just an assumption.
source to share