SemaphoreSlim semaphoreSlim = new(1, 1); await foreach (var batch in batches) { try { await semaphoreSlim.WaitAsync(); var records = batch.AsCollection(); totalBatches++; totalBatches += records.Count; await WriteToParquet(memoryStream, records); } finally { semaphoreSlim.Release(); } }