/// <summary> /// build a process wrapper that wraps a process runned within the provided process start infos in a separated thread that wait the process end and then call the callback function if not null /// </summary> /// <param name="psi"></param> /// <returns></returns> public static ProcessWrapper ThreadRunGetExitCode( sys.ProcessStartInfo psi, ProcessCounter pc = null, Action <int> callBack = null, Action <string> stdOutCallBack = null, Action <string> stdErrCallBack = null) { var sw = new ProcessWrapper { EndOfStreams = 0, PC = pc }; if (pc != null) { pc.Increase(); } InitPSI(psi); sw.StdOutCallBack = stdOutCallBack; sw.StdErrCallBack = stdErrCallBack; sw.Process = sys.Process.Start(psi); if (stdOutCallBack != null) { (sw.StdOutCallBackThread = new Thread(() => { sw.ReadStdOut(); })).Start(); } if (stdErrCallBack != null) { (sw.StdErrCallBackThread = new Thread(() => { sw.ReadStdErr(); })).Start(); } Action lcallBack = null; if (pc != null) { lcallBack = pc.Decrease; } sw.ThreadRunner = new Thread(() => { sw.WaitForExitGetExitCode(callBack); }); sw.ThreadRunner.Start(); return(sw); }
/// <summary> /// build a process wrapper that wraps a process runned within the provided process start infos in a separated thread that wait the process end and then call the callback function if not null /// </summary> /// <param name="psi"></param> /// <returns></returns> public static ProcessWrapper ThreadRun(sys.ProcessStartInfo psi, ProcessCounter pc = null, Action callBack = null, Action <string> stdOutCallBack = null, Action <string> stdErrCallBack = null) { var sw = new ProcessWrapper { EndOfStreams = 0, PC = pc }; if (pc != null) { pc.Increase(); } InitPSI(psi); sw.StdOutCallBack = stdOutCallBack; sw.StdErrCallBack = stdErrCallBack; sw.Process = sys.Process.Start(psi); if (stdOutCallBack != null) { (sw.StdOutCallBackThread = new Thread(() => { sw.ReadStdOut(); })).Start(); } if (stdErrCallBack != null) { (sw.StdErrCallBackThread = new Thread(() => { sw.ReadStdErr(); })).Start(); } Action lcallBack = null; if (pc != null) { lcallBack = pc.Decrease; } sw.CallBack = callBack; sw.ThreadRunner = new Thread(() => { sw.WaitForExit(lcallBack); }); sw.ThreadRunner.Start(); sw.ThreadRunner.Join(); // FGZ 19/5/2018 - découpler pour rétro compat return(sw); }
/// <summary> /// build a process wrapper that wraps a process runned within the provided process start infos in a separated thread that wait the process end and then call the callback function if not null /// </summary> /// <param name="psi"></param> /// <returns></returns> public static ProcessWrapper ThreadRun(sys.ProcessStartInfo psi, ProcessCounter pc = null) { var sw = new ProcessWrapper { EndOfStreams = 0 }; if (pc != null) { pc.Increase(); } InitPSI(psi); sw.Process = sys.Process.Start(psi); Action callBack = null; if (pc != null) { callBack = pc.Decrease; } sw.PC = pc; sw.ThreadRunner = new Thread(() => { sw.WaitForExit(callBack); }); sw.ThreadRunner.Start(); return(sw); }