public SequentialMediaReaderAndProcessor(ICallback callback, CancellationToken cancellation, int processingQueueSize = 64) { this.callback = callback; this.cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellation); this.threadLocalStates = new List <ThreadLocalHolder>(); this.threadLocal = new ThreadLocal <ThreadLocalHolder>(() => { var holder = new ThreadLocalHolder() { State = callback.InitializeThreadLocalState() }; lock (this.threadLocalStates) this.threadLocalStates.Add(holder); return(holder); }); this.processingQueueSize = processingQueueSize; this.inEnumerator = callback.ReadRawDataFromMedia(cancellationTokenSource.Token).GetEnumerator(); this.outEnumerator = CreateEnumerator().GetEnumerator(); }