Skip to content

Instantly share code, notes, and snippets.

@Schandlich
Created May 23, 2014 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Schandlich/45692056cd09005ce1c8 to your computer and use it in GitHub Desktop.
Save Schandlich/45692056cd09005ce1c8 to your computer and use it in GitHub Desktop.
C# Parallel Interview Question
class Program
{
static void Main(string[] args)
{
Random rand = new Random();
var currentInt = 0;
int[] tasks = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; // Should have used F#.
Parallel.ForEach(tasks, (x) =>
{
currentInt = x;
Thread.Sleep(rand.Next(1000, 5000));
Console.WriteLine(string.Format("{0} is done processing.", currentInt));
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment