Calling Console.WriteLine from multiple threads

五迷三道 提交于 2019-12-17 03:20:06

问题


Why does Console.WriteLine work from multiple threads?


回答1:


The console class handles the thread synchronization for you.

From the documentation of Console:

I/O operations using these streams are synchronized, which means multiple threads can read from, or write to, the streams.




回答2:


There is a bug in .NET 4.5 CLR which makes Console.WriteLine not work from multiple threads if you use Console.ReadKey. It is fixed in some Windows versions, but in 8.1 Windows Update does not find it yet.

Infrequent hangs in a multi-threaded C# console application when using Console.Writeline() or Console.Write()

Using Console.WriteLine in a Timer why it would appear to exit?




回答3:


Multiple threads write to the same output when using Console.WriteLine, generally your screen by default.



来源:https://stackoverflow.com/questions/1079980/calling-console-writeline-from-multiple-threads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!