Skip to content

Instantly share code, notes, and snippets.

@luisdeol
Created November 12, 2017 14:38
Show Gist options
  • Save luisdeol/cd0b3e0032cc6bdc5c8b12033ab6787e to your computer and use it in GitHub Desktop.
Save luisdeol/cd0b3e0032cc6bdc5c8b12033ab6787e to your computer and use it in GitHub Desktop.
Using the Parallel Class
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