i'm facing a strange problem with a Timer in a Windows service. is my first windows service, so for start to learn i decide to create a service that each 10 seconds write in a .txt file what time is it. i add the timer but looks like the timer never start. can you help me to understand where i'm wrong? here my code:
namespace testtimer
{
public partial class TestTimer : ServiceBase
{
public TestTimer()
{
InitializeComponent();
timer.Interval = 10000;
timer.Enabled = true;
}
protected override void OnStart(string[] args)
{
timer.Start();
}
protected override void OnStop()
{
}
private void timer_Tick(object sender, EventArgs e)
{
string date = System.DateTime.Now.ToString();
StreamWriter wr = new StreamWriter(@"C:\Users\xxx\Desktop\Test\testtimer.txt", true);
wr.WriteLine("\n" + "The Time is:" + "\t" + date);
wr.Close();
}
}
}
where i'm wrong?
thanks a lot for your help :)