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.
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.
And now, have a look at the result when I run.
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.
And then I called them by Invoke method like below.
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
Top comments (0)