Created
November 12, 2017 14:38
-
-
Save luisdeol/cd0b3e0032cc6bdc5c8b12033ab6787e to your computer and use it in GitHub Desktop.
Using the Parallel Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MultiThreadingExamples | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Priting Even numbers using Parallel.For"); | |
Parallel.For(0, 10, i => | |
{ | |
if (i % 2 == 0) | |
{ | |
Console.WriteLine(i); | |
} | |
Thread.Sleep(1000); | |
}); | |
Console.WriteLine("Priting Even numbers using Parallel.ForEach"); | |
var fromOnetoTen = Enumerable.Range(0, 10); | |
Parallel.ForEach(fromOnetoTen, i => | |
{ | |
if (i % 2 == 0) | |
{ | |
Console.WriteLine(i); | |
} | |
Thread.Sleep(1000); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment