using System;
using System.Collections;
using System.Threading;
using System.IO;

namespace ThreadLibrary
{
   public class FileIO
   {
      public void WriteToFile(object o)
      {
         ArrayList al = (ArrayList)o;

         Console.WriteLine(al[0].ToString());

         try
         {
             Monitor.Enter(this);

            FileStream fs = new FileStream("sync.txt", FileMode.Append);
            StreamWriter sw = new StreamWriter(fs);
            
            for (int i = 1; i < 10000; i++)
            {
               sw.WriteLine(i.ToString());
            }
            
            sw.Flush();
            sw.Close();

            Console.WriteLine("fertig!");
         }
         catch (IOException e)
         {
            Console.WriteLine(e.ToString());
         }
         finally
         {
            //abschliessende Arbeiten
             Monitor.Exit(this);
         }
      }
   }
}