DEV Community

Ali Kolahdoozan
Ali Kolahdoozan

Posted on

1

Parallel Class in .NET ! – Part 3

Image description

It is time to write the third part as I promised. Parallel.Foreach and Parallel.ForeachAsync already explained so the only one left is Parallel.Invoke.

You can find the second part link here :
https://dev.to/alikolahdoozan/parallel-class-in-net-part-2-hoh

Let’s go for creating a new region for Parallel.Invoke at first. All we have had so far should be commented out.

Image description

Let’s go for introducing Parallel.Invoke by some examples.
By using Parallel.Invoke , you can fire multiple lambda functions in a same Invoke !. Let’s see what we can do in a real example.

Image description

And now, have a look at the result when I run.

Image description

As I was expecting, the result is not sequential again since it would be run in parallel.

Another example, I have created 2 static methods like below.

Image description

And then I called them by Invoke method like below.

Image description

That’s it. You are familiar with Parallel class in .NET now…

Lazy to write 3-5 line of simple code ?. I have provided the Github link for you :

https://github.com/AliCharper/ParallelClassExercise

Wish you all the best...
We ❤️ .NET !
Ali

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up