本文介绍了在启动C#过程中无需分散注意力的控制台窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我弄清楚如何启动一个进程。但我的问题是现在的控制台窗口(在这种情况下,7z格式)弹出最前面挡住了我的视野和我的去除重点打断我的句子或W / E我在做每隔几秒钟。它非常恼人的,我怎么prevent这种情况的发生。我以为CreateNoWindow解决了,但它没有。

请注意:有时控制台需要用户输入(替换文件或不)。因此,它隐藏完全可能是一个问题的很好。

这是我目前的code。

 无效DoSomething的(...)
{
    myProcess.StartInfo.FileName = ...;
    myProcess.StartInfo.Arguments = ...;
    myProcess.StartInfo.CreateNoWindow = TRUE;
    myProcess.Start();
    myProcess.WaitForExit();
}


解决方案

如果我没有记错,这为我工作

 工艺过程=新工艺();//从打开一个新窗口停止进程
process.StartInfo.RedirectStandardOutput =真;
process.StartInfo.UseShellExecute = FALSE;
process.StartInfo.CreateNoWindow = TRUE;//安装可执行文件和参数
process.StartInfo.FileName = @C:\\ TEST.EXE
process.StartInfo.Arguments =--test;// 走
的Process.Start();

我一直在使用这从C#控制台应用程序中启动另一个过程,它从启动它在一个单独的窗口,而不是在同一个窗口藏在心里停止应用程序。

I figure out how to launch a process. But my problem now is the console window (in this case 7z) pops up frontmost blocking my vision and removing my focus interrupting my sentence or w/e i am doing every few seconds. Its extremely annoying, how do i prevent that from happening. I thought CreateNoWindow solves that but it didnt.

NOTE: sometimes the console needs user input (replace file or not). So hiding it completely may be a problems a well.

This is my current code.

void doSomething(...)
{
    myProcess.StartInfo.FileName = ...;
    myProcess.StartInfo.Arguments = ...;
    myProcess.StartInfo.CreateNoWindow = true;
    myProcess.Start();
    myProcess.WaitForExit();
}
解决方案

If I recall correctly, this worked for me

Process process = new Process();

// Stop the process from opening a new window
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;

// Setup executable and parameters
process.StartInfo.FileName = @"c:\test.exe"
process.StartInfo.Arguments = "--test";

// Go
process.Start();

I've been using this from within a C# console application to launch another process, and it stops the application from launching it in a separate window, instead keeping everything in the same window.

这篇关于在启动C#过程中无需分散注意力的控制台窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 07:36