我正在寻找使用 Process.Start() 来启动可执行文件,但我想继续执行程序,无论可执行文件是成功还是失败,或者 Process.Start() 本身是否引发异常。
我有这个:
myProcess.StartInfo.UseShellExecute = false;
// You can start any process, HelloWorld is a do-nothing example.
myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
我知道您可以将其添加到 try catch
try
{
myProcess.StartInfo.UseShellExecute = false;
// You can start any process, HelloWorld is a do-nothing example.
myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
如果找不到文件,尝试捕获版本不会失败?如何处理其他异常,如 InvalidOperationException Win32Exception ObjectDisposedException
如果失败,目标只是继续使用代码......
非常感谢!