Console.WriteLine(quot;quot;); gets stuck(Console.WriteLine();卡住)
问题描述
有时当我执行上述语句时,程序会在控制台应用程序中冻结.如果我中断,我将无法移动到下一行.我需要重置缓冲区吗?
Sometimes when I execute the above statement, the program freezes in a console application. If I break, I can't move to the next line. Do I need to reset a buffer or something?
这是一个在屏幕上显示消息的批处理应用程序.有没有人经历过这个并设法解决它.这似乎是一个新事物.我正在使用 Visual Studio 2017 教授版.
It's a batch process application that displays messages to the screen. Has anyone experienced this and managed to resolve it. It seems to be a new thing. I'm using Visual Studio 2017 Prof. edition.
WriteLine
停止的函数如下.sMessage
的值为空白".
The function where WriteLine
stalls is below. The value of sMessage
is blank "".
static void Display(string sMessage, DisplayColours eColour = DisplayColours.White)
{
if (eColour == DisplayColours.Yellow)
Console.ForegroundColor = ConsoleColor.Yellow;
if (eColour == DisplayColours.Blue)
Console.ForegroundColor = ConsoleColor.Cyan;
if (eColour == DisplayColours.Green)
Console.ForegroundColor = ConsoleColor.Green;
if (eColour == DisplayColours.Red)
Console.ForegroundColor = ConsoleColor.Red;
if (eColour == DisplayColours.Magenta)
Console.ForegroundColor = ConsoleColor.Magenta;
if (oFptr != null)
{
oFptr.WriteLine(sMessage);
oFptr.Flush();
}
Console.WriteLine(sMessage);
Console.ForegroundColor = ConsoleColor.White;
}
推荐答案
可能导致这种情况的一个原因是,如果您单击控制台窗口以开始选择文本,换句话说,第一步从控制台窗口中复制文本.发生这种情况时,对控制台窗口的写入将挂起,直到您返回控制台窗口并按 Enter 删除选择框.
One thing that can cause this, is if you click on the console window in such a way that it starts to select text, in other words, the first step in copying text out of the console window. When this happens, a write to the console window will hang until you return to the console window and press Enter to remove the selection box.
这篇关于Console.WriteLine("");卡住的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Console.WriteLine("");卡住


- 使用 rss + c# 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01