Timers in c#

  • Thread starter Thread starter GDumencu
  • Start date Start date
G

GDumencu

I have a C# program that have to run all the time. For
some reasons I cannot make it a service.
This program has 3 timers and by time to time ( days or
weeks) one of them stops. Some times, starts working again
after several hours.
Each timer records a message to a file at the beginning
and at the end of each timer.
I can see the last message from that timer and than
nothing.

I have to mention that in timer handler I'm using COM
objects written in C++ and another object of a .NET class
(include in project) that uses COM+ objects.

Thanks.
===========================================
private static System.Timers.Timer m_Timer1;
....
m_Timer1 = new System.Timers.Timer();
m_Timer1.Elapsed+=new ElapsedEventHandler
(OnTimedEventProcessTimer1);
m_Timer1.Interval = 1000;
m_Timer1.AutoReset=false;
m_Timer1.Enabled=true;

......
protected void OnTimedEventProcessTimer1(object source,
ElapsedEventArgs e)
{
((System.Timers.Timer)source).Enabled=false;
bool b=false;
<...>.<...> myobj=null; //a COM object
try
{
....first message recorded
........
....last message recorded
}
catch (Exception ex)
{
}
finally
{
((System.Timers.Timer)source).Enabled=true;
((System.Timers.Timer)source).Start();
}
 
Back
Top