当 UseShellExecute 为 false 时,遵循 ProcessStartInfo.WindowStyle

之前,只有在UseShellExecutetrue时才遵循WindowStyle。 即使UseShellExecutefalse,此更改也遵循WindowStyle

旧行为

在进行此更改之前,以下代码已启动进程,就像尚未指定WindowStyle一样,因为UseShellExecute = false。 也就是说,窗口可见,不隐藏。

using System.Diagnostics;

ProcessStartInfo startInfo = new()
{
    FileName = @"C:\Windows\System32\notepad.exe",
    UseShellExecute = false,
    WindowStyle = ProcessWindowStyle.Hidden
};

var process = Process.Start(startInfo);
process!.WaitForExit();

新行为

从 .NET 8 开始,即使是使用UseShellExecute = false启动的进程也遵循WindowStyle

上一个行为部分中的代码启动进程,隐藏了窗口。

引入的版本

.NET 8 预览版 6

中断性变更的类型

此更改为行为更改

更改原因

一些方案需要更改衍生进程的窗口的样式(特别是隐藏它)。

此更改会影响指定WindowStyle的代码,即使它不受正确支持也是如此。 例如,WPF 的事件触发顺序现在已更改。 要缓解中断性变更,请不要在ProcessStartInfo中指定WindowStyle

受影响的 API