Discussion:
Windows service with timer doesn't work in Windows 2003 server
(too old to reply)
Dhilip Kumar
2005-01-20 17:28:42 UTC
Permalink
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
Greg Merideth
2005-01-21 04:19:59 UTC
Permalink
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.
Post by 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
Dhilip Kumar
2005-01-21 05:22:36 UTC
Permalink
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
Post by Greg Merideth
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.
Post by 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
Willy Denoyette [MVP]
2005-01-21 10:25:48 UTC
Permalink
Post by Dhilip Kumar
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?
Dhilip Kumar
2005-01-24 14:24:39 UTC
Permalink
Willy,

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

Dhilip
Post by Willy Denoyette [MVP]
Post by Dhilip Kumar
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 Denoyette [MVP]
2005-01-24 16:30:56 UTC
Permalink
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.
Post by Dhilip Kumar
Willy,
I am using timer instance from the Server.Timers namespace. I hope that
should be fine!
Dhilip
Post by Willy Denoyette [MVP]
Post by Dhilip Kumar
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?
Continue reading on narkive:
Loading...