public static Wait ( Func |
||
action | Func |
|
waitAction | System.Action | |
리턴 | void |
/// <summary> /// Main processing loop for internal thread. /// </summary> private void MainLoop() { while (!ShouldExit) { //if: //1) Single worker is allowed when idle //2) This worker is idle //3) All other workers are idle // Then: pause all other workers, and switch to single worker mode if (_workerCollection.Configuration.SingleWorkerWhenNoWorkFound && IdleStatus == WorkerIdleStatus.Idle && _workerCollection.AllWorkersAreIdle) { _workerCollection.PauseWorkers(); } if (ShouldExit) { return; } MessageProcessing.Handle(); } if (MessageProcessing != null && MessageProcessing.AsyncTaskCount > 0) { WaitOnAsyncTask.Wait(() => MessageProcessing.AsyncTaskCount > 0, () => _log.LogWarning( $"Unable to terminate because async requests have not finished. Current task count is {MessageProcessing.AsyncTaskCount}")); } }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (!disposing) { return; } if (Interlocked.Increment(ref _disposeCount) != 1) { return; } if (_asyncTaskCount > 0) { WaitOnAsyncTask.Wait(() => _asyncTaskCount > 0, () => _log.Warn( $"Unable to terminate because async requests have not finished. Current task count is {_asyncTaskCount}")); } }
/// <summary> /// Looks for messages to process /// </summary> private void MainLoop() { while (!ShouldExit) { //wait, if told to do so _pauseEvent.Wait(); if (ShouldExit) { return; } MessageProcessing.Handle(); } if (MessageProcessing != null && MessageProcessing.AsyncTaskCount > 0) { WaitOnAsyncTask.Wait(() => MessageProcessing.AsyncTaskCount > 0, () => _log.Warn( $"Unable to terminate because async requests have not finished. Current task count is {MessageProcessing.AsyncTaskCount}")); } }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> protected override void Dispose(bool disposing) { if (!disposing) { return; } if (Interlocked.Increment(ref _disposeCount) != 1) { return; } if (Interlocked.Read(ref _waitingOnAsyncTasks) > 0) { WaitOnAsyncTask.Wait(() => Interlocked.Read(ref _waitingOnAsyncTasks) > 0, () => Log.Warn( $"Unable to terminate because async requests have not finished. Current task count is {Interlocked.Read(ref _waitingOnAsyncTasks)}")); } _clearQueue.Stop(); base.Dispose(true); }