Learn how to use the more advanced version of theParallel.For loop. At the same time, explore how to cancel a long-running task.
- [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.…
Make sure we use system, not threading,…
Released
4/2/2018- Thread safety and affinity
- Signaling
- Task Parallel Library (TPL) basics
- PLINQ introduction
- Task-based Asynchronous Pattern (TAP)
Share this video
Embed this video
Video: Parallel.For with thread local