DotNetWorkQueue.Queue.WaitForDelegate.Wait C# (CSharp) Method

Wait() public static method

Waits for an action to complete
public static Wait ( Func action ) : bool
action Func The action.
return bool
        public static bool Wait(Func<bool> action)
        {
            return Wait(action, null);
        }
        /// <summary>

Same methods

WaitForDelegate::Wait ( Func action, System.TimeSpan timeout ) : bool

Usage Example

Exemplo n.º 1
0
        /// <summary>
        /// Stops the specified primary worker
        /// </summary>
        /// <param name="worker">The worker.</param>
        public void StopPrimary(IPrimaryWorker worker)
        {
            Guard.NotNull(() => worker, worker);

            _waitForEventOrCancel.Set();
            _waitForEventOrCancel.Cancel();

            //stop is a blocking operation for the primary worker
            Task.Run(worker.Stop);

            //wait for workers to stop
            WaitForDelegate.Wait(() => worker.Running, _configuration.TimeToWaitForWorkersToStop);
            if (worker.Running)
            {
                worker.AttemptToTerminate();
            }

            //attempt to cancel workers if any are still running
            if (worker.Running)
            {
                _cancelWorkSource.CancellationTokenSource.Cancel();
                WaitForDelegate.Wait(() => worker.Running, _configuration.TimeToWaitForWorkersToCancel);
                if (worker.Running)
                {
                    worker.AttemptToTerminate();
                }
            }

            //force kill workers that are still running by aborting the thread, or waiting until work has completed
            if (worker.Running)
            {
                worker.TryForceTerminate();
            }
        }
All Usage Examples Of DotNetWorkQueue.Queue.WaitForDelegate::Wait
WaitForDelegate