title: Improve performance writing 10 million records to text file using windows service
body: <p>I'm fetching more than 10 millions of records from database and writing to a text file. It takes hours of time to complete this operation. Is there any option to use TPL features here?</p>
  
  <p>It would be great if someone could get me started implementing this with the TPL.</p>
  
  <pre><code>using (FileStream fStream = new FileStream("d:\\file.txt", FileMode.OpenOrCreate,     FileAccess.ReadWrite))
  {
      BufferedStream bStream = new BufferedStream(fStream);
      TextWriter writer = new StreamWriter(bStream);
      for (int i = 0; i &lt; 100000000; i++)
      {
          writer.WriteLine(i);
      }
      bStream.Flush();
      writer.Flush(); // empty buffer;
      fStream.Flush();
  }
  </code></pre>