[Solved] Discussion: Threading in .NET [closed]


Here are my two cents:

Thread: When you feel comfortable enough that you can handle all the IDEAL number of threads. This is almost always never the case. It is hear for people that would cry out that I want REAL threads not the .NET thread pool. If you don’t want to ask this question : Optimal number of threads per core don’t go with thread.

ThreadPool: This was the .net answer to in the box solution for the optimal number of threads. The API however was not the best. For new projects use TPL.

BackgroundWorker: If you are want to start threading from your GUI app with easy post backs. This provides the simplest API.

Dispatcher : Like you said. Just for calling back to the GUI thread. It is Vital for that. There is no other way you could use it anyways without some obscure code I do not know.
Note: It is not called delegate. Delegate is what you pass into a Dispatcher to dispatch.

Task Parallel Library : This came with .net 4. Recommended that you use it for new projects.

Parallel: No you got this wrong. Parallel.For will not return control until the entire loop is complete. It is there as a convenience when all you want to do is execute a loop in parallel. Great for mapping an input to an output e.g x -> x*2. Using Parallel.For (or ForEach) you can run this on multiple threads (again the number is decided by .NET) to run the loop faster. Check out: http://www.lovethedot.net/2009/02/parallelfor-deeper-dive-parallel.html

solved Discussion: Threading in .NET [closed]