.NET - WindowStyle = 隐藏 vs. CreateNoWindow = true?
属性有什么区别?
WindowStyle = Hidden
或
CreateNoWindow = true
当我启动一个新进程时,如果使用ProcessStartInfo
类的
When I start a new process, what difference does it make if I use the
WindowStyle = Hidden
or the
CreateNoWindow = true
property of the ProcessStartInfo
class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如Hans所说,WindowStyle是传递给进程的一个建议,应用程序可以选择忽略它。
CreateNoWindow 控制控制台如何为子进程工作,但它不能单独工作。
CreateNoWindow 与 UseShellExecute 结合使用,如下所示:
在没有任何窗口的情况下运行进程:
在子进程自己的窗口(新控制台)中运行子
进程 在父进程的控制台窗口中运行子进程
As Hans said, WindowStyle is a recommendation passed to the process, the application can choose to ignore it.
CreateNoWindow controls how the console works for the child process, but it doesn't work alone.
CreateNoWindow works in conjunction with UseShellExecute as follows:
To run the process without any window:
To run the child process in its own window (new console)
To run the child process in the parent's console window
CreateNoWindow 仅适用于控制台模式应用程序,它不会创建控制台窗口。
WindowStyle 仅适用于本机 Windows GUI 应用程序。这是传递给 WinMain() 入口点。第四个参数,nCmdShow,告诉它如何显示其主窗口。这与桌面快捷方式中的“运行”设置显示的提示相同。请注意,“隐藏”不是一个选项,很少有正确设计的 Windows 程序会满足该请求。由于这对用户造成了影响,他们无法再激活该程序,只能使用任务管理器将其杀死。
CreateNoWindow only applies to console mode apps, it won't create the console window.
WindowStyle only applies to native Windows GUI apps. It is a hint passed to the WinMain() entry point of such a program. Fourth argument, nCmdShow, telling it how to show its main window. This is the same hint that appears as the "Run" setting in a desktop shortcut. Note that "hidden" is not an option there, few properly designed Windows program honor that request. Since that snookers the user, they can't get the program activated anymore and can only kill it with Task Manager.
使用 Reflector,它看起来像
WindowStyle
UseShellExecute<,则使用 >
/code> 已设置,否则使用
CreateNoWindow
。在 MSDN 的示例中,您可以看到他们如何设置它:
在另一个示例中,它就在下面,因为
UseShellExecute
默认为 trueUsing Reflector, it looks like
WindowStyle
is used ifUseShellExecute
is set, otherwise it usesCreateNoWindow
.In MSDN's example, you can see how they set it:
In the other example, its just below because
UseShellExecute
is defaulted to true