title: Windows service with timer
body: <p>I have created a windows service with timer in c#.net. it works fine while i debug/build the project in visual studio but it does not perform its operation after installation.</p>
  
  <p>What might be the reason behind this ?</p>
  
  <p>code :   </p>
  
  <pre><code>public partial class Service1 : ServiceBase
  {
          FileStream fs;
          StreamWriter m_streamWriter;
          Timer tm = new Timer();
  
          public Service1()
          {
              InitializeComponent();
  
              this.ServiceName = "timerservice";
  
              tm.Interval = 2000;
              tm.Tick += new EventHandler(PerformOperations);
              tm.Start();
  
              fs = new FileStream(@"c:\mcWindowsService.txt", FileMode.OpenOrCreate, FileAccess.Write);
  
              m_streamWriter = new StreamWriter(fs);
              m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
          }
  
          private void PerformOperations(object sener, EventArgs e)
          {
              //StreamWriter swr = new StreamWriter("c:\\test_from_database.txt",true);
  
              try
              {
                  OdbcConnection con = new OdbcConnection("DSN=liquor_data");
  
                  OdbcDataAdapter adp = new OdbcDataAdapter("", con);
  
                  DataSet ds = new DataSet();
  
                  string sql = "select * from item_group";
                  adp.SelectCommand.CommandText = sql;
  
                  adp.Fill(ds, "item_group");
  
                  foreach (DataRow dr in ds.Tables["item_group"].Rows)
                  {
                      //      swr.Write(dr["group_name"].ToString() + "\t\t" + DateTime.Now.TimeOfDay.ToString() + "\n");
  
                      //Console.WriteLine(dr["group_name"].ToString() + "\t\t" + DateTime.Now.TimeOfDay.ToString() + "\n");
                      m_streamWriter.WriteLine(dr["group_name"].ToString() + "\t\t" + DateTime.Now.TimeOfDay.ToString() + "\n");
                  }
  
                  m_streamWriter.Flush();
              }
  
              catch (Exception ex)
              {
                  // swr.Write("Error :"+ ex.Message + "\t\t" + DateTime.Now.TimeOfDay.ToString() + "\n"); }
              }
          }
      }
  </code></pre>