Search code examples
c#processsystem.diagnostics

How to Dispose a process, where you don't want to wait for exit


I have a process p in my application, which will be closed by the user at some point while my application is still running. But I want my application to run on while p is running. How do I then dispose p after p were closed by the user?


Solution

  • Use p.Exited += (emitter, args) => ((Process) emitter).Dispose(); before starting p