Task parallel with C#

Dnx_7
Dnx_7 used Ask the Experts™
on
Hi experts,

i have infinite loop to do misc jobs

with .NET 2.0, i used  thread.QueueUserWorkItem but since .NET 4.0, i use task with :

Task.Factory.StartNew(void(), null);

It works but i read some article that the "task.factory.startnew()" use the new threadpool shipped with .net 4 and this is not for infinite loop because the threadpool can run out of free slot.

that's why i would like to use something that is optimize for multicore programming
do the old "thread.start()" is stilll good to use for multicore programming?

thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2014

Commented:
Yes. You can use any approach.
QueueUserWorkItem works as well.

Author

Commented:
thank you but i read that the "queueuserworkitem" should be avoided since .NET 4
because it uses the "old" threadpool not the new one shipped with the last framework...

am i wrong?

thank you
Most Valuable Expert 2012
Top Expert 2014

Commented:

Author

Commented:
Thank you codecruiser, i read again some articles and here what i understood :

when you compile your app in the framework 2.0, it will use the "old" threadpool shipped with that framework.

When you compile in 3.5 or 4.0, it will use the new threadpool that is optimized for TASK/Parallel and seems that will the QueueUserWorkItem, it has been optimized too for multicore machine

am i right?
Most Valuable Expert 2012
Top Expert 2014
Commented:
I am not sure about that. If you select .NET 4 from target framework list on above link, it does not say anything about multicore etc. The only thing it mentions regarding versions is that in 2, the user principal is propagated to threads.

For multicore though, you would need to use the Parallel library.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial