Servizio di Windows con timer

Ho creato un servizio Windows con timer in c # .net. funziona bene mentre eseguo il debug / build del progetto in Visual Studio ma non esegue le sue operazioni dopo l’installazione.

Quale potrebbe essere la ragione di questo?

codice :

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"); } } } }