protected virtual void Execute() { ReadChunksQueue.WaitForInput(); _executing = true; using (var threadPool = new GeneralThreadPool(CancellationToken, Options.MaxBuffers)) { while ((_reading || ReadChunksQueue.Count > 0) && !ErrorOccured) { IChunk chunk = null; if (ReadChunksQueue.TryDequeue(out chunk)) { threadPool.Enqueue(() => { ExecuteChunk(chunk); ExecutedChunksQueue.Enqueue(chunk); }); } else { Thread.Sleep(10); } } threadPool.StopAdding(); threadPool.WaitForCompletion(); } _executing = false; }
protected virtual void ReadStream(Stream inputStream) { _reading = true; while (true && !ErrorOccured) { IChunk chunk = ReadChunk(inputStream); if (chunk.Body.Length == 0) { break; } ReadChunksQueue.Enqueue(chunk); } _reading = false; }