/// <summary>Starts a new stop watch.</summary> /// <returns>The started stop watch.</returns> public static DateTimeStopWatch StartNew() { var result = new DateTimeStopWatch(); result.Start(); return(result); }
/// <summary> /// Waits for process completion. /// </summary> /// <param name="timeout">maximum time to wait.</param> /// <param name="waitCallBack">Callback while waiting for process exit (should not use up more then 1000ms).</param> /// <param name="throwEx">Throw exception if the process does not exit in time.</param> /// <returns></returns> public bool Wait(TimeSpan timeout, WaitAction waitCallBack, bool throwEx) { IStopWatch watch = DateTimeStopWatch.StartNew(); bool exit = false; while (!exit && (watch.Elapsed < timeout)) { if (Task.WaitAll(new Task[] { errorTask, outputTask }, 1)) { return(true); } waitCallBack?.Invoke(out exit); } if (throwEx) { throw new TimeoutException(); } return(false); }