Matt

Matt

  • NA
  • 3
  • 0

C# Service

Feb 14 2009 12:15 PM
I am new to writing a windows service, could you please have a look at the following code so you can tell me why the timer_tick event never fires?

Thanks :-)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.IO;

namespace MyNewService
{
    public partial class MyNewService : ServiceBase
    {

        TextWriter tw = new StreamWriter("log.txt");

        public MyNewService()
        {
            InitializeComponent();
                                 
            tw.WriteLine(DateTime.Now + " COSHH Service has been installed correctly!");
            tw.Close();
        }

        protected override void OnStart(string[] args)
        {
            timer1.Start();
           
        }

        protected override void OnStop()
        {
           timer1.Stop();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
           
            tw.WriteLine(DateTime.Now + " hello from COSHH Updater!");
            tw.Close();
        }
    }
}


Answers (3)