I'm trying to save my data to csv file. When the rate is small(2,000/s to save), it works well. But when increase to 20,000/s, it works slowly.
class Channel
{
List<double> RawData { get; set; }
...
}
-----------------------------------
var channels = new List<Channel>();
// after fetch the data
var sw = new StreamWriter(FileStream, Encoding.Default);
for (i = 0; channels.First().RawData.Count; i ++)
{
string line = DateTime.Now.ToString() + ",";
line += string.Join(',', channels.Select(c => c.RawData[i]));
sw.WriteLine(line);
sw.Flush();
}
When the count of RawData of each channel reach to 20,000, the app will work slowly. Is there any solution to speed up the generation of line?