Windows service with timer doesn't work in Windows 2003 server

  • Thread starter Thread starter Dhilip Kumar
  • Start date Start date
D

Dhilip Kumar

Hi all,

I have developed a windows service using the windows service project
template in VS.NET. I have used three controls in the service, a timer,
performance counter and a message queue control. The service will "sleep"
for 'n' seconds using the timer control and whenever the timer_elapsed event
occurs, I use the performance counter object to determine availability of
few resources. Based on the availability of resources, I use the message
queue control to put messages into a local private queue. The service uses
LocalService account and reads a few registry keys in the OnStart() method
and then waits for the timer_elapsed event.

The issue is the all too familiar "it works on my system" kind!! It works
perfectly fine in my development system (installed using installutil) which
is a WinXP SP2 with .Net 1.1.4322 and the timer also gets triggered
properly. But when I install the same service in a Windows 2003 server the
timer never gets triggered!! The server also has the same version of .Net
framework but I'm just lost as to why the timer doesn't get triggered
there!! There are no errors/warnings generated in the event log too so its
all the more confusing. I also tried creating a setup project with custom
actions and then installed the same in the Win2003 server but the
timer_elapsed event never gets triggered!!

Replies will be very helpful!! Btw, I have set the AutoReset property of
the timer control to false to have control over when the timer starts
ticking again, but I have made sure that I start off the timer
appropriately.

Thanks
Dhilip Kumar
 
Silly question but you are using a System timer and not a form's timer
right?

Also, what, if any, additional processing does the service do that might
be causing a security issue under the server environment. I agree,
service debugging is a pain.

What I do, while making the code a pain in the ass to read, is add
literally about 100 of these

#if _SERVICE_DEBUG_
eventLog.Additem("[method]::[counter]");
#endif

so that I will see "eventLog.Additem("_addHash::11");" in my code and
about 5-6 lines below that "eventLog.Additem("_addHash::12");".

It's a sad yet, fully workable way to watch line by line count what is
going on log wise in the service. When you see 10.11.12.. and no more
numbers, it pins down the cause between 12 and 13. When your finished
just undefine the pragma and recompile to get rid of the tracking.
 
Greg,

Thanks very much for your reply. Yes, it was a security issue! The timer
control I used was a server timer, but I was using Local Service account. I
changed it to LocalSystem it worked! Interesting, because I don't recollect
seeing any security precautions in the documentation while using the server
timer!!

Dhilip Kumar

Greg Merideth said:
Silly question but you are using a System timer and not a form's timer
right?

Also, what, if any, additional processing does the service do that might
be causing a security issue under the server environment. I agree,
service debugging is a pain.

What I do, while making the code a pain in the ass to read, is add
literally about 100 of these

#if _SERVICE_DEBUG_
eventLog.Additem("[method]::[counter]");
#endif

so that I will see "eventLog.Additem("_addHash::11");" in my code and
about 5-6 lines below that "eventLog.Additem("_addHash::12");".

It's a sad yet, fully workable way to watch line by line count what is
going on log wise in the service. When you see 10.11.12.. and no more
numbers, it pins down the cause between 12 and 13. When your finished
just undefine the pragma and recompile to get rid of the tracking.

Dhilip said:
Hi all,

I have developed a windows service using the windows service project
template in VS.NET. I have used three controls in the service, a timer,
performance counter and a message queue control. The service will
"sleep" for 'n' seconds using the timer control and whenever the
timer_elapsed event occurs, I use the performance counter object to
determine availability of few resources. Based on the availability of
resources, I use the message queue control to put messages into a local
private queue. The service uses LocalService account and reads a few
registry keys in the OnStart() method and then waits for the
timer_elapsed event.

The issue is the all too familiar "it works on my system" kind!! It
works perfectly fine in my development system (installed using
installutil) which is a WinXP SP2 with .Net 1.1.4322 and the timer also
gets triggered properly. But when I install the same service in a
Windows 2003 server the timer never gets triggered!! The server also has
the same version of .Net framework but I'm just lost as to why the timer
doesn't get triggered there!! There are no errors/warnings generated in
the event log too so its all the more confusing. I also tried creating
a setup project with custom actions and then installed the same in the
Win2003 server but the timer_elapsed event never gets triggered!!

Replies will be very helpful!! Btw, I have set the AutoReset property of
the timer control to false to have control over when the timer starts
ticking again, but I have made sure that I start off the timer
appropriately.

Thanks
Dhilip Kumar
 
Dhilip Kumar said:
Greg,

Thanks very much for your reply. Yes, it was a security issue! The timer
control I used was a server timer, but I was using Local Service account.
I changed it to LocalSystem it worked! Interesting, because I don't
recollect seeing any security precautions in the documentation while using
the server timer!!

Dhilip Kumar

There are no security issues associated, both LocalSystem and Local service
should work.
What scares me a bit is that you are talking about a "Time Control" using
"server timer", mind to explain exactly what control you are talking about?
More importantly, what timer class are you using?

Willy?
 
Willy,

I am using timer instance from the Server.Timers namespace. I hope that
should be fine!

Dhilip
 
Guess you mean System.Timers namespace. Using this kind of timers should
work without a problem irrespective the security context.
I'm sure you hit another issue with your service.

Willy.
 
Back
Top