System.Threading.Tasks - Limit the number of concurrent Tasks

Posted by James on Stack Overflow See other posts from Stack Overflow or by James
Published on 2010-05-24T16:46:25Z Indexed on 2010/05/24 16:51 UTC
Read the original article Hit count: 535

Filed under:
|
|
|

I have just started to look at the new "System.Threading.Tasks" goodness in .Net 4.0, and would like to know if there is any build in support for limiting the number of concurrent tasks that run at once, or if this should be manually handled.

E.G: If I need to call a calculation method 100 times, is there a way to set up 100 Tasks, but have only 5 execute simultaneously? The answer may just be to create 5 tasks, call Task.WaitAny, and create a new Task as each previous one finishes. I just want to make sure I am not missing a trick if there is a better way to do this.

Thanks for any help.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about ASP.NET