private void TryWriteInputSegment(Stream destination) { // If there is an available thread && here is data in the input buffer if (parallelProcessor.AvailableThreadsExist()) { Segment segmentsBufferSegment = TryGetSegmentsBufferSegment(); if (segmentsBufferSegment != null) { // Write segment in a separate thread parallelProcessor.Process(() => { // Start writing followed by saving exception if it happens lock (destination) exceptionConsumingSegmentStreamWriter.Write(destination, segmentsBufferSegment); }); } } }