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.

Parallel.For with thread local

Parallel.For with thread local - C# Tutorial

From the course: Advanced Threading in C#

Start my 1-month free trial

Parallel.For with thread local

- [Instructor] So now that we've seen how parallel execution ends up being better than the normal execution in certain cases and vice versa. We've also seen a very simple parallel dot for loop. We've also seen a little complicated parallel dot for each. Now let's see how cancellation works and while we do that, we'll also show you a little bit more complicated for loop. So let's say we want to create a list using Enumerable.Range and I want to give it a range between zero to all the way to 10 and then let's just convert this to an array. So we get the values right here. So if I were to run this real quick, you can see if we have a list, zero all the way to 10. Now getting the sum of something like this is fairly straightforward and very simple. Now this is not a typical example of using parallel, but the goal here is not to show you an example of using parallel execution but to show you how cancellation works. So the way that cancellation works is by using a cancellation token source.…

Contents