I noticed that an I/O race condition is triggered when using Console.WriteLine.
The following exception will be thrown,
System.IndexOutOfRangeException: Probable I/O race condition detected while copying memory. The I/O package is not thread safe by default. In multithreaded applications, a stream must be accessed in a thread-safe way, such as a thread-safe wrapper returned
by TextReader's or TextWriter's Synchronized methods. This also applies to classes like StreamWriter and StreamReader.
This is very hard to reproduce but it happened in a production environment.
To reproduce this, I have to use the following code on a WPF application project.
The project must be compiled and the application run from the output folder. It must not run in debug mode.
Parallel.For(0, 1000, new ParallelOptions() { MaxDegreeOfParallelism = 10 }, (_) => { try { for (int i = 0; i < 10; i++) { Console.WriteLine("test message to the out stream"); Thread.Sleep(100); Console.Error.WriteLine("test message to the error stream"); } } catch (Exception ex) { //Debugger.Launch(); WriteToMessageArea(ex.Message); //throw; } });Has anyone experience this issue?