Created
May 23, 2014 17:09
-
-
Save Schandlich/45692056cd09005ce1c8 to your computer and use it in GitHub Desktop.
C# Parallel Interview Question
This file contains 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
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