码迷,mamicode.com
首页 > Windows程序 > 详细

.NET - WindowStyle = hidden vs. CreateNoWindow = true?

时间:2020-06-30 17:21:05      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:print   within   round   you   form   link   log   row   obj   

.NET - WindowStyle = hidden vs. CreateNoWindow = true?

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:

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);

 

ProcessStartInfo.CreateNoWindow Property

true if the process should be started without creating a new window to contain it; otherwise, false. The default is false.

Remarks

If the UseShellExecute property is true or the UserName and Password properties are not null, the CreateNoWindow property value is ignored and a new window is created.

.NET Core does not support creating windows directly on Unix-like platforms, including macOS and Linux. This property is ignored on such platforms.

 

ProcessStartInfo.UseShellExecute Property

true if the shell should be used when starting the process; false if the process should be created directly from the executable file. The default is true on .NET Framework apps and false on .NET Core apps.

Remarks

Setting this property to false enables you to redirect input, output, and error streams.

The word "shell" in this context (UseShellExecute) refers to a graphical shell (similar to the Windows shell) rather than command shells (for example, bash or sh) and lets users launch graphical applications or open documents.

Note

UseShellExecute must be false if the UserName property is not null or an empty string, or an InvalidOperationException will be thrown when the Process.Start(ProcessStartInfo) method is called.

When you use the operating system shell to start processes, you can start any document (which is any registered file type associated with an executable that has a default open action) and perform operations on the file, such as printing, by using the Process object. When UseShellExecute is false, you can start only executables by using the Process object.

Note

UseShellExecute must be true if you set the ErrorDialog property to true.

If you set the WindowStyle to ProcessWindowStyle.Hidden, UseShellExecute must be set to true.

WorkingDirectory

The WorkingDirectory property behaves differently depending on the value of the UseShellExecute property. When UseShellExecute is true, the WorkingDirectory property specifies the location of the executable. If WorkingDirectory is an empty string, it is assumed that the current directory contains the executable.

When UseShellExecute is false, the WorkingDirectory property is not used to find the executable. Instead, it is used only by the process that is started and has meaning only within the context of the new process. When UseShellExecute is false, the FileName property can be either a fully qualified path to the executable, or a simple executable name that the system will attempt to find within folders specified by the PATH environment variable.

 

.NET - WindowStyle = hidden vs. CreateNoWindow = true?

标签:print   within   round   you   form   link   log   row   obj   

原文地址:https://www.cnblogs.com/chucklu/p/13214745.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!