CmisSync.Lib.Queueing.SyncEventQueue.Listen C# (CSharp) Метод

Listen() приватный Метод

private Listen ( BlockingCollection queue, ISyncEventManager manager, WaitHandle waitHandle ) : void
queue BlockingCollection
manager ISyncEventManager
waitHandle System.Threading.WaitHandle
Результат void
        private void Listen(BlockingCollection<ISyncEvent> queue, ISyncEventManager manager, WaitHandle waitHandle) {
            Logger.Debug("Starting to listen on SyncEventQueue");
            while (!queue.IsCompleted) {
                ISyncEvent syncEvent = null;

                // Blocks if number.Count == 0
                // IOE means that Take() was called on a completed collection.
                // Some other thread can call CompleteAdding after we pass the
                // IsCompleted check but before we call Take.
                // In this example, we can simply catch the exception since the
                // loop will break on the next iteration.
                try {
                    syncEvent = queue.Take();
                } catch (InvalidOperationException) {
                }

                if (syncEvent != null) {
                    try {
                        if (this.suspend) {
                            Logger.Debug("Suspending sync");
                            waitHandle.WaitOne();
                            Logger.Debug("Continue sync");
                        }

                        manager.Handle(syncEvent);
                    } catch (CmisConnectionException connectionException) {
                        this.AddEvent(new CmisConnectionExceptionEvent(connectionException));
                    } catch(Exception e) {
                        Logger.Error(string.Format("Exception in EventHandler on Event {0}: ", syncEvent.ToString()), e);
                    }

                    if (syncEvent is ICountableEvent) {
                        var category = (syncEvent as ICountableEvent).Category;
                        if (category != EventCategory.NoCategory) {
                            lock (this.subscriberLock) {
                                this.fullCounter.Decrease(syncEvent as ICountableEvent);
                                this.categoryCounter.Decrease(syncEvent as ICountableEvent);
                            }
                        }
                    }
                }
            }

            Logger.Debug("Stopping to listen on SyncEventQueue");
        }
    }