public void Run() { System.Diagnostics.Debug.WriteLine("Starting ZkClient event thread."); try { while (!this.tokenSource.IsCancellationRequested) { ZkEvent zkEvent = this._events.Take(); int eventId = this._eventId.GetAndIncrement(); System.Diagnostics.Debug.WriteLine("Delivering event #" + eventId + " " + zkEvent); try { zkEvent.RunAction(); } catch (ThreadInterruptedException) { this.tokenSource.Cancel(); } catch (Exception e) { Logger.Error("Error handling event " + zkEvent, e); } System.Diagnostics.Debug.WriteLine("Delivering event #" + eventId + " done"); } } catch (ThreadInterruptedException) { System.Diagnostics.Debug.WriteLine("Terminate ZkClient event thread."); } }
public void Send(ZkEvent zkEvent) { if (!this.tokenSource.IsCancellationRequested) { System.Diagnostics.Debug.WriteLine("New event: " + zkEvent); this._events.Add(zkEvent); } }