当执行的Process.Start(),你需要将它包装一个使用?将它、Process、Start

2023-09-04 23:50:03 作者:丶猪是的念来过倒字名

当你开始一个过程,不要计较结果是这样行吗?

 的Process.Start(XXX);
 

还是应该做到这一点。

 使用(的Process.Start(XXX)){}
 
解决python运行时Error Cannot start process, the working directory is not a directory

解决方案

纵观 Process.dispose(布尔)方法的实现表明,它调用关闭()进程实例。这又清理本机进程的​​句柄所以它可能不是一个坏主意。

这也清理,使用它来检查进程已退出等待处理。

即使你不使用使用(...)阻止终结将在年底赶上这些资源。

When you are starting a process and dont care about the result is this ok?

Process.Start(xxx);

Or should you do this

using (Process.Start(xxx)){}

解决方案

Looking at the implementation of the Process.dispose(bool) method shows that it calls Close() on the Process instance. This in turn cleans up the native process handle so its probably not a bad idea.

It also cleans up a wait handle that it uses to check if the process has exited.

Even if you don't use the using (...) block the finalizer will catch these resources in the end.