进程不会在c#中最小化

Dio*_*Nt. 6 c# firefox process

pro.StartInfo.FileName =  @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";

pro.StartInfo.Arguments = a;
pro.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;

pro.Start();
Run Code Online (Sandbox Code Playgroud)

我上面的代码启动Firefox最小化.但Firefox实际上并没有最小化,而是作为普通窗口.我的代码有什么问题?我必须在线程睡100毫秒吗?

C4d*_*C4d 5

试试这个:)

pro.StartInfo.FileName =  @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";

pro.StartInfo.Arguments = a;
pro.UseShellExecute = true;
pro.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;

pro.Start();
Run Code Online (Sandbox Code Playgroud)

我认为这只有在 Firefox 没有运行的情况下才有效。否则它仍然会打开 Firefox,但不会最小化。如果您想在进程已经启动的情况下最小化自己启动的 Firefox,则需要按照此处ShowWindow所述进行处理。