Why Timer stop working ?

D

Daniele Piccinini

Hallo,

I've writed a C# windows service in VS 2003.
This service use a System.Timers.Timer to periodically call some functions
of a web service.
( Some of this functions required minutes to be executed ).
The timer interval is 1 sec, and each functions 'counts' his number of timer
clock to know when it must be executed.
Sometimes happen that the service don't do his works. I stop the service and
watching the log i note thath the timer has stop 'clocking' some hour ago
( i save the last clock datetime in TmrSystem_Elapsed event handler and i
log this value in the service OnStop function ).
Someone have an idea ?

Thanks.

- Dany -

The code ..

private void TmrSystem_Elapsed(object sender, System.Timers.ElapsedEventArgs
e)
{
DtmLastClock = System.DateTime.Now;

if ( NumFunction1_TimerSteps > 0 )
{
NumFunction1_StepsCount++;

if ( !BolFunction1_Lock && NumFunction1_StepsCount >=
NumFunction1_TimerSteps )
{
BolFunction1_Lock = true;
NumFunction1_StepsCount = 0;
this.Function1();
BolFunction1_Lock = false;
}
}

if ( NumFunction2_TimerSteps > 0 )
{
NumFunction2_StepsCount++;

if ( !BolFunction2_Lock && NumFunction2_StepsCount >=
NumFunction2_TimerSteps )
{
BolFunction2_Lock = true;
NumFunction2_StepsCount = 0;
this.Function2();
BolFunction2_Lock = false;
}
}
}
 
J

John Duval

Hallo,

I've writed a C# windows service in VS 2003.
This service use a System.Timers.Timer to periodically call some functions
of a web service.
( Some of this functions required minutes to be executed ).
The timer interval is 1 sec, and each functions 'counts' his number of timer
clock to know when it must be executed.
Sometimes happen that the service don't do his works. I stop the service and
watching the log i note thath the timer has stop 'clocking' some hour ago
( i save the last clock datetime in TmrSystem_Elapsed event handler and i
log this value in the service OnStop function ).
Someone have an idea ?

Thanks.

- Dany -

The code ..

private void TmrSystem_Elapsed(object sender, System.Timers.ElapsedEventArgs
e)
{
DtmLastClock = System.DateTime.Now;

if ( NumFunction1_TimerSteps > 0 )
{
NumFunction1_StepsCount++;

if ( !BolFunction1_Lock && NumFunction1_StepsCount >=
NumFunction1_TimerSteps )
{
BolFunction1_Lock = true;
NumFunction1_StepsCount = 0;
this.Function1();
BolFunction1_Lock = false;
}
}

if ( NumFunction2_TimerSteps > 0 )
{
NumFunction2_StepsCount++;

if ( !BolFunction2_Lock && NumFunction2_StepsCount >=
NumFunction2_TimerSteps )
{
BolFunction2_Lock = true;
NumFunction2_StepsCount = 0;
this.Function2();
BolFunction2_Lock = false;
}
}



}- Hide quoted text -

- Show quoted text -

Hi Daniele,
I'm not sure it applies to your situation, but you might want to check
out this article:
FIX: When a .NET Framework based application uses the
System.Threading.Timer class, the timer event may not be signaled in
the .NET Framework 1.1 SP1

http://support.microsoft.com/?id=900822

I ran into this a while back when I had timers that stopped firing.
Hope it helps,
John
 
D

Daniele Piccinini

John Duval said:
Hi Daniele,
I'm not sure it applies to your situation, but you might want to check
out this article:
FIX: When a .NET Framework based application uses the
System.Threading.Timer class, the timer event may not be signaled in
the .NET Framework 1.1 SP1

http://support.microsoft.com/?id=900822

I ran into this a while back when I had timers that stopped firing.
Hope it helps,
John

Thank you John, the problem may be this.
The service is installed on Windows Server 2003 sbs sp1. Do i need to
install Windows server 2003 sp2 or (better) do you know if there is an
update of the framework ?
Thanks

- Dany -
 
K

ktrvnbq02

The service is installed on Windows Server 2003 sbs sp1. Do i need to
install Windows server 2003 sp2 or (better) do you know if there is an
update of the framework ?

Also see the following, which may be relevant to your situation:

BUG: The Elapsed event of the System.Timers.Timer class is not raised
in a Windows service

http://support.microsoft.com/kb/842793

(although I'm not sure I believe the commentary in the steps to repro
in that linked article.)


Matt
 
S

Steven Cheng[MSFT]

Thank for Matt's informative input.

Hi Daniele,

I think the further bug entry Matt has refered could be helpful to you:

#FIX: When a .NET Framework based application uses the
System.Threading.Timer class, the timer event may not be signaled in the
.NET Framework 1.1 SP1
http://support.microsoft.com/kb/900822/

If feel the problem you met is aligned to the bug entry, you can directly
contact the CSS (follow the link in the kb) and request for the hotfix.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mr. Arnold

Daniele Piccinini said:
Hallo,

I've writed a C# windows service in VS 2003.
This service use a System.Timers.Timer to periodically call some functions
of a web service.
( Some of this functions required minutes to be executed ).
The timer interval is 1 sec, and each functions 'counts' his number of
timer clock to know when it must be executed.
Sometimes happen that the service don't do his works. I stop the service
and watching the log i note thath the timer has stop 'clocking' some hour
ago ( i save the last clock datetime in TmrSystem_Elapsed event handler
and i log this value in the service OnStop function ).
Someone have an idea ?

I don't like using Timers in a NT Service, because of the reasons you're
posting about.

I always spawn a thread and use a Thread.Sleep(wait time) in a While True
Loop to execute code on a timed basis in a NT Service application.
 
D

Daniele Piccinini

Thank you Steven. Now i contact the CSS and request for the hotfix.

- Dany -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top