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.
Degree of parallelism - C# Tutorial
From the course: Advanced Threading in C#
Degree of parallelism
- [Instructor] Now we'll look at an example where we could use the degree of parallelism as we talked about earlier. I will call it PLinqDegreeParallel. So a good example would be to just ping a few websites that are out there and let's take the important ones. We can say list of strings and we'll call it sites, or websites, equals new list of string. Websites.Add we could have initialized inline but we can also do this. And the last one to be microsoft.com. And next what we want to do is ping these websites and get the response in PingReply. We use System.Net.NetworkInformation. Once that reference is resolved we should be able to get the responses and we'll use a Plinq query. We use websites and first thing, as always, is going to be AsParallel. Once we have that we are going to say WithDegreeOfParallelism and, in this case, we can just say sites.count because we want three different calls going to three different websites so it makes more sense to have DegreeOfParallelism to be…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.