/// <summary> /// The method the thread executes. The thread executes the Callback delegate for each item it takes off the queue. /// </summary> private void ProcessWhileHasInput() { try { // Keep the thread alive unless the exit event is signaled while (true) { ItemMetaData itemData; while (_inputs.TryDequeue(out itemData)) { SpoolerAction(itemData.Item); } SpoolerEmpty?.Invoke(); break; } } catch (Exception ex) { // Normal call to abort for the thread, call in finalize will necessarily end here if // the thread has not already been stopped NotifyException(this, ex); } }
private void ProcessWhileHasInput(CancellationToken cancelToken) { try { if (cancelToken.IsCancellationRequested) { return; } // Keep the thread alive unless the exit event is signaled ItemMetaData itemData; while (_inputs.TryDequeue(out itemData)) { if (itemData.HoldOnItem) { Stop(); return; } RaiseItemSpooledEvent(itemData.Item); } SpoolerEmpty?.Invoke(); } catch (Exception ex) { // Normal call to abort for the thread, call in finalize will necessarily end here if // the thread has not already been stopped RaiseException(this, ex); } }
/// <summary> /// The method the thread executes. The thread executes the Callback delegate for each item it takes off the queue. /// </summary> private void ProcessWhileHasInput() { try { // Keep the thread alive unless the exit event is signaled while (true) { int iWaitEvent = WaitHandle.WaitAny(_operationHandles); if (_operationHandles[iWaitEvent] == _trafficEvent) { ItemMetaData itemData; while (_inputs.TryDequeue(out itemData)) { // allow stop/resume using itemActionEvent signaling if (_itemActionEvent.WaitOne()) { try { if (itemData.HoldOnItem) { _itemActionEvent.Reset(); } RaiseItemSpooledEvent(itemData.Item); } catch (Exception ex) { RaiseException(this, ex); } } } SpoolerEmpty?.Invoke(); } else if (_operationHandles[iWaitEvent] == _exitEvent) { break; } } } catch (Exception ex) { // Normal call to abort for the thread, call in finalize will necessarily end here if // the thread has not already been stopped RaiseException(this, ex); } }