Windows控制台应用程序被卡住(需求的关键preSS) [英] Windows Console Application Getting Stuck (Needs Key Press)

查看:1440
本文介绍了Windows控制台应用程序被卡住(需求的关键preSS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了运行像这样不同的组件控制台程序:

 无效的start(){
而(真){
     做一点事();
     Thread.sleep代码(1000 * 5);
}
}

我的主入口点样子[伪杂交code]

  Thread.Start(Componenet1.Start);
Thread.Start(Componenet2.Start);而(真){
     Console.Writeline(运行);
     Thread.sleep代码(1000 * 5);
}

有没有Console.Reads任何地方。我的问题是有时候应用程序将会运行很好,但随后停止,如果我preSS窗口上的任意键将重新开始工作。这种情况相当罕见,但我有这个方案在自动化环境中部署了100多个上虚拟机的运行24/7

此外在电脑上我有一些AHK脚本和其他东西,操纵鼠标,但如果说有什么用它做不知道。

另外请注意,有时CPU真的可以达到100%的机器上运行,所以也许线程的优先级是一个问题?

SOLUTION :你需要禁用快速编辑模式。这里正在C#code要做到这一点:

  // http://msdn.microsoft.com/en-us/library/ms686033(VS.85).aspx
    函数[DllImport(KERNEL32.DLL)]
    公共静态外部布尔SetConsoleM​​ode(IntPtr的hConsoleHandle,UINT dwMode);    私人常量UINT ENABLE_EXTENDED_FLAGS = 0x0080;    静态无效的主要(字串[] args)
    {
         IntPtr的手柄= Process.GetCurrentProcess()MainWindowHandle。
         SetConsoleM​​ode(手柄,ENABLE_EXTENDED_FLAGS);


解决方案

如果用户不小心点击到黑色控制台窗口,光标变成一个装满白色矩形,和应用程序挂起,在接下来的Console.Write声明,直到另外集团公司而成。

这是当启用了快速编辑模式控制台窗口的一般特征。

为了禁用该功能,就应该取消您的应用程序的控制台窗口在运行时的快速编辑模式选项。

I have a console program that has different components that run like this:

void start() {
while(true){
     DoSomething();
     Thread.Sleep(1000*5);
}
}

My main entry point looks like [pseudo-ish code]

Thread.Start(Componenet1.Start);
Thread.Start(Componenet2.Start);

while(true){
     Console.Writeline("running");
     Thread.Sleep(1000*5);
}

There are no Console.Reads anywhere. My problem is SOMETIMES the application will be running great but then stop and if I press any key on the window it will start working again. This happens fairly infrequently but I have this program deployed on 100+ VM's running 24/7 in an automated environment.

Also on the computer I have some AHK scripts and other stuff that manipulate the mouse but not sure if that has anything to do with it.

Also note that sometimes the CPU can really be running at 100% on the machines so maybe thread priority is an issue?

SOLUTION: You need to disable quick edit mode. Here is working C# code to do this:

 // http://msdn.microsoft.com/en-us/library/ms686033(VS.85).aspx
    [DllImport("kernel32.dll")]
    public static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);

    private const uint ENABLE_EXTENDED_FLAGS = 0x0080;

    static void Main(string[] args)
    {
         IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;
         SetConsoleMode(handle, ENABLE_EXTENDED_FLAGS);

解决方案

If the user accidentally clicks into the black console window, the cursor changes to a filled white rectangle, and the app hangs at the next Console.Write statement, until another clic is made.

It is a generic feature of the Console window when its "QuickEdit Mode" is enabled.

In order to disable that feature, you should uncheck the "QuickEdit Mode" option of your app's console window at run-time.

这篇关于Windows控制台应用程序被卡住(需求的关键preSS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆