From the course: Advanced Threading in C#

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

TPL demo

TPL demo - C# Tutorial

From the course: Advanced Threading in C#

Start my 1-month free trial

TPL demo

- [Instructor] Now it's time to use TPL. Again, we'll create a console project. I'll just call it 'TPL Intro'. I'm sure you're familiar with a simple for-loop. In this case, we have 'I', which is zero, and then we can have 'N', or the number, or iterations. And I'll just say 10. So it's going to go from zero all the way to nine, and that makes it 10 iterations. And then we can do something here. So I could possibly say, 'Console dot WriteLine', and then it could... print the ID.... or the iteration count, which in this case is 'I'. So it'll print zero all the way to nine in 10 different lines. How do we create a parallel version of the same? In order to do that, we use 'parallel dot for-loop', and we'll have zero, and in this case, 'N', which is the upper limit, or the upper count, which is 10. And now, we'll use a lambda expression. Now, this lambda expression is an action, and we can add any amount of lines right here. We could've done the same thing here, put it in a method, and…

Contents