简体   繁体   English

从Windows 7命令行运行时,为什么我的C#程序会经常暂停?

[英]Why does my C# program pause so often when running from the Windows 7 command line?

I've had this problem with several different C# apps. 我在几个不同的C#应用​​程序中遇到过这个问题。 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. 他们将当前步骤打印到控制台(旧版本通过System.Console.WriteLine(),新版本通过log4net的ConsoleAppender),所以我总是从命令提示符运行它们。 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? 我该如何解决?

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. 使用鼠标单击窗口时,可能会意外创建文本选择。

The simplest assumption - an application goes to the branch with the call Console.ReadLine() . 最简单的假设 - 应用程序通过调用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. 最后,尝试在程序挂起期间在调试器中启动Break-command等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM