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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay