If I kill a System.Diagnostics.Process with .Kill(), do I also need to call .Close()?

后端 未结 2 1506
你的背包
你的背包 2021-02-18 17:36

Using C# 4.0, I\'ve created a System.Diagnostics.Process that I expect to take a short amount of time to run. If for some reason the process hasn\'t exited after so

2条回答
  •  一生所求
    2021-02-18 18:23

    Process.Kill() and Process.Close() both internally call Close() on the private SafeProcessHandle object associated with the process. However, Process.Close() also explicitly resets several other internal members.

    Since Process implements IDisposable, you should always call Close() on it when you are done, or wrap it in a using block.

提交回复
热议问题