![](/img/trans.png)
[英]C# Start Excel using Process Not Working in Firefox Native Messaging but works in Chrome
[英]C# headless chrome from Process Start not working
我需要从网络核心控制台应用程序调用无头 chrome。 但是使用此代码,应用程序运行并卡在无所事事且无打印,pdf 也没有创建。 终端中相同的 arguments 按预期工作。
public static bool TakeScreenshot2()
{
try
{
var procStartInfo = new ProcessStartInfo()
{
FileName = "google-chrome",
Arguments = "--headless --disable-gpu --print-to-pdf=final.pdf http://www.google.com/",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
var proc = new Process { StartInfo = procStartInfo };
proc.Start();
var output = proc.StandardOutput.ReadToEnd();
Console.WriteLine(output);
string error = proc.StandardError.ReadToEnd();
Console.WriteLine(error);
return proc.ExitCode == decimal.Zero ? true : false;
}
finally
{
// do something
}
}
您应该等待该过程完成
var proc = new Process { StartInfo = procStartInfo };
proc.Start();
proc.WaitForExit();
您可以在退出后使用proc.ExitCode
检查它是否成功
如果你不想阻塞它完成的线程单元,你可以运行它,你 function 需要异步
await Task.Run(() => proc.WaitForExit());
或使用 Process 事件Exited
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.