Improve CSV Generation Speed

In my application i am writing huge amount of data to a csv file, the CSV generation takes more than 10 minutes. Below is my code, any input would be greatly appreciated

using (var writer = new StreamWriter(filePath))
using (var csv = new CsvWriter(writer))
{
csv.WriteHeader();
csv.NextRecord();
csv.Configuration.QuoteAllFields = true;
csv.WriteRecords(formatedBoxes);
}

CsvWriter is not part of .Net, so you should report this to wherever you found that type.

Suggest me an approach to write csv in .NET with 100 columns and 10k rows

Some guesses:

  1. Try turning off AutoFlush and some formatting settings (like indentation) on the related classes.
  2. Provide the CsvWriter constructor with a filename, instead of a hi-level writer.
.NET Foundation Website | Blog | Projects | Code of Conduct