Created
June 26, 2011 10:41
-
-
Save jittuu/1047498 to your computer and use it in GitHub Desktop.
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 int count = 100000; | |
static int runningCount = 0; | |
static void Main(string[] args) | |
{ | |
var dict = new Dictionary<Guid, string>(); | |
var mre = new ManualResetEvent(false); | |
for (int i = 0; i < 10; i++) | |
{ | |
ThreadPool.QueueUserWorkItem((obj) => | |
{ | |
mre.WaitOne(); | |
while (true) | |
{ | |
try | |
{ | |
var key = Guid.NewGuid(); | |
dict[key] = "A"; // this line throws IndexOutOfRangeException | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.ToString()); | |
} | |
if (Interlocked.Increment(ref runningCount) >= count) | |
{ | |
Console.WriteLine("ThreadId: {0} done!", Thread.CurrentThread.ManagedThreadId); | |
break; | |
} | |
} | |
}); | |
} | |
Console.WriteLine("Press Enter to start"); | |
Console.Read(); | |
mre.Set(); | |
Console.WriteLine("starting"); | |
Console.ReadLine(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment