using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.IO;

namespace ThreadLibrary
{
   public class FileIO
   {
      public void WriteToFile()
      {
         try
         {
            FileStream fs = new FileStream("sync.txt", FileMode.Append);
            StreamWriter sw = new StreamWriter(fs);
            
            for (int i = 1; i < 1000; i++)
            {
               sw.WriteLine(Thread.CurrentThread.Name);
               Thread.Sleep(5);
            }
            
            sw.Flush();
            sw.Close();
            fs.Close();
         }
         catch (IOException e)
         {
            Console.WriteLine(e.ToString());
         }
         finally
         {
            //abschließende Arbeiten
         }
      }
   }
}