.NET - WindowStyle = hidden vs. CreateNoWindow = true? [英] .NET - WindowStyle = hidden vs. CreateNoWindow = true?
问题描述
当我开始一个新进程时,如果我使用
When I start a new process, what difference does it make if I use the
WindowStyle = Hidden
或
CreateNoWindow = true
ProcessStartInfo
类的属性?
推荐答案
正如Hans所说,WindowStyle是传递给进程的推荐,应用可以选择忽略它.
As Hans said, WindowStyle is a recommendation passed to the process, the application can choose to ignore it.
CreateNoWindow 控制控制台如何为子进程工作,但它不能单独工作.
CreateNoWindow controls how the console works for the child process, but it doesn't work alone.
CreateNoWindow 与 UseShellExecute 结合使用,如下所示:
CreateNoWindow works in conjunction with UseShellExecute as follows:
在没有任何窗口的情况下运行进程:
To run the process without any window:
ProcessStartInfo info = new ProcessStartInfo(fileName, arg);
info.CreateNoWindow = true;
info.UseShellExecute = false;
Process processChild = Process.Start(info);
在自己的窗口中运行子进程(新控制台)
To run the child process in its own window (new console)
ProcessStartInfo info = new ProcessStartInfo(fileName, arg);
info.UseShellExecute = true; // which is the default value.
Process processChild = Process.Start(info); // separate window
在父控制台窗口中运行子进程
To run the child process in the parent's console window
ProcessStartInfo info = new ProcessStartInfo(fileName, arg);
info.UseShellExecute = false; // causes consoles to share window
Process processChild = Process.Start(info);
这篇关于.NET - WindowStyle = hidden vs. CreateNoWindow = true?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!