.net 从多个线程调用 Console.WriteLine

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1079980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 12:58:00  来源:igfitidea点击:

Calling Console.WriteLine from multiple threads

.netconsole.writeline

提问by Reed Copsey

Why does Console.WriteLine work from multiple threads?

为什么 Console.WriteLine 从多个线程工作?

回答by Reed Copsey

The console class handles the thread synchronization for you.

控制台类为您处理线程同步。

From the documentation of Console:

Console的文档中:

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

使用这些流的 I/O 操作是同步的,这意味着多个线程可以读取或写入流。

回答by Jure ?pik

There is a bug in .NET 4.5 CLR which makes Console.WriteLine notwork 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.

.NET 4.5 CLR 中存在一个错误,如果您使用 Console.ReadKey ,它会使 Console.WriteLine无法从多个线程工作。它在某些 Windows 版本中已修复,但在 8.1 Windows Update 中尚未找到。

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

使用 Console.Writeline() 或 Console.Write() 时,在多线程 C# 控制台应用程序中很少挂起

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

在计时器中使用 Console.WriteLine 为什么它会出现退出?

回答by Chris Ballance

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

使用 时Console.WriteLine,多个线程写入相同的输出,默认情况下通常是您的屏幕。