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.

Concurrency bag

Concurrency bag - C# Tutorial

From the course: Advanced Threading in C#

Start my 1-month free trial

Concurrency bag

- [Instructor] Now I'd like to show you how we can use PLINQ for all statement, which actually is faster than the for each statement we've been using. If you remember, the parallel.for or parallel.for each statements, they actually execute in parallel, but they do not really merge or combine the data. You have to have an additional step to do it on your own. Whereas, the for all statement takes care of that for you. So let's say we have a list, equals enumerable.range, and we can take a different number this time. Let's say two thousand all the way to five thousand, and we have a query, which his list.asparallel. And then we have a condition, which is where the number, whatever number we have, we're going to do a percent with let's say 25, and if it is equal to 0, that means if it is divisible by 25, then what we'll do is we'll use something called concurrent bag, and you'll have to resolve this reference. It will be in system.collections.concurrent. And this is a pretty handy tool…

Contents