コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: TestProducer.cs プロジェクト: gugu91/bread-winner
        protected override bool WaitForWorkOrCancellation(CancellationToken cancellationToken)
        {
            WaitForWorkOrCancellationCalledWith = cancellationToken;

            return(WaitAction?.Invoke(cancellationToken) ?? false);
        }