/// <summary> /// Release all process-related resources. /// The child process will be killed if still running /// </summary> public void Dispose() { try { Kill(); } catch (Win32Exception) { } StdErr.Dispose(); StdOut.Dispose(); StdIn.Dispose(); var processMainThread = Interlocked.Exchange(ref _pi.hThread, IntPtr.Zero); if (processMainThread != IntPtr.Zero) { Kernel32.CloseHandle(processMainThread); } var processHandle = Interlocked.Exchange(ref _pi.hProcess, IntPtr.Zero); if (processHandle != IntPtr.Zero) { Kernel32.CloseHandle(processHandle); } }