B
Björn
Hi,
I have problems using the timer object in a C# Windows Service
In my OnStart() Method of the Windows Service I declare a timer object
"Timer myTimer = 0;"
Than I have a loop "for(i=0;i<=3;i++)" where I set "myTimer = new Timer;"
and the Eventhandler "myTimer.Elapsed += new
ElapsedEventHandler(OnTimedEvent);"
Now I have four different timers running. But only the last keep running,
the other three stops working after a while. And I don´t know why?
Can it be that I run into a thread problem?
All four timers call the same method (OnTimedEvent). First I thought I have
a synchronisation problem, so I set a Lock statement around the code of the
method
"private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
lock(lockvar)
{
//my code
}
}"
I don´t know what´s going wrong, has anyone an idea???
Best regards
Björn
I have problems using the timer object in a C# Windows Service
In my OnStart() Method of the Windows Service I declare a timer object
"Timer myTimer = 0;"
Than I have a loop "for(i=0;i<=3;i++)" where I set "myTimer = new Timer;"
and the Eventhandler "myTimer.Elapsed += new
ElapsedEventHandler(OnTimedEvent);"
Now I have four different timers running. But only the last keep running,
the other three stops working after a while. And I don´t know why?
Can it be that I run into a thread problem?
All four timers call the same method (OnTimedEvent). First I thought I have
a synchronisation problem, so I set a Lock statement around the code of the
method
"private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
lock(lockvar)
{
//my code
}
}"
I don´t know what´s going wrong, has anyone an idea???
Best regards
Björn