Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In .NET 4, does BeginInvoke and Task use the same threadpool?

.NET 4 introduced a brand new thread pool design accessed by the Task Parallel library. But if I have old code that uses Delegate.BeginInvoke, will those be executed by that new thread pool? Or is the old thread pool still in the runtime somewhere?

like image 939
projectshave Avatar asked Mar 10 '11 19:03

projectshave


1 Answers

They both use the same ThreadPool. ThreadPool.QueueUserWorkItem does, as well.

However, Delegate.BeginInvoke has extra overhead when compared to Task.Factory.StartNew, and does not take advantages of many of the features in the ThreadPool, such as work stealing or the new debugging features. I would recommend refactoring this to use the new Task features as time permits.

like image 200
Reed Copsey Avatar answered Sep 28 '22 16:09

Reed Copsey