How to run 2 StreamWriters in parallel

236 views Asked by At

Recently I was working on a project to write a csv file and an XML file at the same time. They contain the same metadata information, how to open two StreamWriters in C# at the same time?

1

There are 1 answers

7
Alexander Bell On BEST ANSWER

The question is too broad so the answer is generic. In order "to write a csv file and an XML file at the same time" you have to implement sort of multi-threading, using either Task Parallel Library (TPL - recommended) or other technique available in .NET, and run the aforementioned procedures on two different threads (in either blocking or non-blocking mode).

More details on TPL implementation: https://msdn.microsoft.com/en-us/library/dd537609%28v=vs.110%29.aspx.

Hope this may help.