简体   繁体   中英

What can be the reasons why windows service OnStart is not called?

I've installed my serivce but cannot start it.

I get dialog window with the message:

Windows could not start the WU Distribution Service service on Local Computer. Error 1053: The service did not respond to the start or control request in a timely fashion.

And two EventLog entries: the first with the same message and the second one with:

A timeout was reached (30000 milliseconds) while waiting for the WU Distribution Service service to connect.

My serivce class has default generated constructor with the only call to InitializeComponent() so nothing heavy.

Just to check how long OnStart runs I inserted Debug.WriteLine with times tamps and added TextWriterTraceListener with Debug.AutoFlush set to true.
No log file was created, thus OnStart was not called.
To be absolutely sure I just throw exception inside OnStart but still get no messages about exception.

I need to know what can be the reasons why OnStart is not called.

You'll have to debug to see what happens. You can add more prints, I would recommend eliminating complications and just write to a file stream instead of Debug listeners.

You can attach debugger to a running process, see How to: Debug Windows Service Applications , but that requires the service to be up and running. If it hungs at startup you still have a good chance because you can inspect the hung state and understand what happens.

If you need to debug service first moments of life then you'll need to graduate to a true debugger. See KB824344 How to debug Windows services , specifically the Configure a service to start with the WinDbg debugger attached, I usually use gflags, way more elegant than registry. You'll need to bridge a remote to your service attached WinDbg from your own session, see Remote Debugging Using WinDbg .You can debug managed code in WinDbg, is not exactly the posh experience VS is doing, but is the real deal on what the machine is doing.

An easy thing to test first is how does your executable behaves when started under the service account. If service is running as localsystem then use psexec -i -s .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM