/// <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); }
protected override bool WaitForWorkOrCancellation(CancellationToken cancellationToken) { WaitForWorkOrCancellationCalledWith = cancellationToken; return(WaitAction?.Invoke(cancellationToken) ?? false); }