I\'m having difficulty trying to determine the cause of a timeout in a Windows Service I\'ve created with C#. I\'ve spent a considerable amount of time looking at several posts
I fixed similar issue by turning off publisher evidence generation in config file. The service also did not have authenticode signing but adding following line immediately fixed the issue on the machine where it has been reproduced consistently.
<runtime>
<generatePublisherEvidence enabled="false" />
</runtime>
Also recommended in this MSDN source:
"We recommend that services use the element to improve startup performance. Using this element can also help avoid delays that can cause a time-out and the cancellation of the service startup. "
Since log4net is not designed to be (in their words) a reliable logging system, I thought it was good practice to write unhandled exceptions to the eventlog (as well as to your log), especially with services.
In general, spawning a background thread from OnStart
is the right thing to do.
For troubleshooting purposes, you could try to give your service more startup time by calling RequestAdditionalTime method from OnStart
. Also, you might want to check if any messages have been written to the Windows EventLog (log "Application", the source should be your service name).
A few things to try:
Add log messages to the top of Main()
, before ServiceBase.Run()
, etc. Assuming you get a log file, how do those timestamps compare to the Windows Event Log?
Create a brand new Service with the New Project Wizard and deploy it as-is. On the problem machines, does it start reliably?
Get process monitor and watch a normal startup. Look for any unexpected network or file I/O.
Make sure your SchedulerService
does not do any work in the constructor, and does not have any statically-initialized dependencies.
Set the Recovery options to restart on first failure. Does that work reliably?
I'd also suspect that log4net is somehow hanging. Maybe the drive where the log is to be created is not ready yet when the machine is booting. Have you tried starting your service delayed?