I am writing a Windows application and I am using a timer. In the OnStart () event of my Windows service, I start a timer, and I want StartTimer () to be called every minute, but nothing happens.
What is wrong here?
thank.
myWinService.cs:
protected override void OnStart(string[] args)
{
timer1.Interval=60000;
timer1.Start();
}
private void StartTimer()
{
FileStream fs = new FileStream(@"c:\temp\mcWindowsService.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs);
m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
m_streamWriter.WriteLine(Environment.UserName.ToString()+tik.ToString());
m_streamWriter.Flush();
}
private void timer1_Tick(object sender, EventArgs e)
{
tik++;
StartTimer();
}
source
share