为什么我的 C# 程序在从 Windows 7 命令行运行时经常暂停?
我在使用几个不同的 C# 应用程序时遇到过这个问题。这些都是我编写的实用程序,旨在让我作为系统管理员的生活更轻松。比如在数据库服务器之间迁移数据之类的事情。
它们将当前步骤打印到控制台(旧版本通过 System.Console.WriteLine(),新版本通过 log4net 的 ConsoleAppender),因此我总是从命令提示符运行它们。当这样做时,他们似乎经常以随机的间隔暂停,直到我按回车键几次。我注意到它们暂停了,因为通常需要一两秒的步骤已经在屏幕上显示了很长时间。按回车键后,事情会再次开始正常处理一段时间。
这是为什么呢?我该如何修复它?
I've had this problem with several different C# apps. These are all utility programs I've written to make my life as a sysadmin easier. Things like migrating data between database servers.
They print their current step to the console (old versions through System.Console.WriteLine(), newer ones through log4net's ConsoleAppender), so I always run them from a command prompt. When doing so, they often seem to pause at random intervals until I hit enter a few times. I notice they're paused because a step that usually takes a second or two has been on the screen for a long time. After hitting enter, things start processing normally again for a while.
Why is this? How can I fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果使用鼠标在命令窗口屏幕上选择文本,通常会暂停正在运行的程序的执行。使用鼠标单击窗口时,您可能会意外创建文本选择。
If you select text on the command window screen using the mouse, it often pauses execution of the program that is running. You might be accidentally creating a text selection when clicking on the window with the mouse.
最简单的假设 - 应用程序通过调用
Console.ReadLine()
转到分支。没有足够的信息来做出任何其他假设。
最后,尝试在程序挂起等期间在调试器中启动Break命令。
The simplest assumption - an application goes to the branch with the call
Console.ReadLine()
.It is not enough information to make any other assumption.
Eventually, try to initiate Break-command in the debugger during the program hanging, etc.