T
thereisnopatchforhumancruelty
Guest
Hi, I have a Windows Service with two timers. In the OnStart method:
checkTimer1.Elapsed += new ElapsedEventHandler(OnCheckTimer1Time);
checkTimer1.Interval = 300000; //5 min
checkTimer1.Enabled = true;
checkTimer2.Elapsed += new ElapsedEventHandler(OnCheckTimer2Time);
checkTimer2.Interval = 600000; //10 min
checkTimer2.Enabled = true;
OnCheckTimer1Time:
private void OnCheckTimer1Time(object source, ElapsedEventArgs e)
{
writeLog("something timer 1");
}
OnCheckTimer2Time:
private void OnCheckTimer2Time(object source, ElapsedEventArgs e)
{
writeLog("something timer 2");
}
and writeLog:
try
{
using (StreamWriter sw = new StreamWriter(@"C:\Users\myuser\Desktop\logFile.txt", true))
sw.WriteLine(line);
}
catch (Exception)
{
return;
}
But the "something timer 2" is never printed on file. I think that this is because 600000 is a multiple of 300000 and when it's the time in which the two event must be called, only the first event is executed.
Can someone tell me why I have this behavior and how I can solve that, protecting my file from the cuncurrent access?
The two timer are of System.Timers components
PS: if I choose 30000 ms e 600121 ms in the timer Interval, in my file I have both the something timer 1 and something timer 2 strings.
Continue reading...
checkTimer1.Elapsed += new ElapsedEventHandler(OnCheckTimer1Time);
checkTimer1.Interval = 300000; //5 min
checkTimer1.Enabled = true;
checkTimer2.Elapsed += new ElapsedEventHandler(OnCheckTimer2Time);
checkTimer2.Interval = 600000; //10 min
checkTimer2.Enabled = true;
OnCheckTimer1Time:
private void OnCheckTimer1Time(object source, ElapsedEventArgs e)
{
writeLog("something timer 1");
}
OnCheckTimer2Time:
private void OnCheckTimer2Time(object source, ElapsedEventArgs e)
{
writeLog("something timer 2");
}
and writeLog:
try
{
using (StreamWriter sw = new StreamWriter(@"C:\Users\myuser\Desktop\logFile.txt", true))
sw.WriteLine(line);
}
catch (Exception)
{
return;
}
But the "something timer 2" is never printed on file. I think that this is because 600000 is a multiple of 300000 and when it's the time in which the two event must be called, only the first event is executed.
Can someone tell me why I have this behavior and how I can solve that, protecting my file from the cuncurrent access?
The two timer are of System.Timers components
PS: if I choose 30000 ms e 600121 ms in the timer Interval, in my file I have both the something timer 1 and something timer 2 strings.
Continue reading...