Re: .Net (C#) Service Fails To Start



Interesting technique - but when my code fails, it does not seem to even get that far, and when it succeeds, I have no need to debug it, and I cannot predict when it will fail.

-ken

Jason wrote:
Having suffered through getting a C# service going, here's a trick that I did that helped me track things down. In your OnStart function, put a line at the beginning like "Thread.Sleep(20000)" and put a breakpoint at the following line. Start your service, then quickly go back into Visual Studio and hit Debug, Processes and attach to your service (you'll probably need to check "Show system processes"). Once you do that, your debugger is attached to the service and you can step through once the Sleep is done and find out where things are going wrong.


Ken Allen wrote:

I have a number of services developed in C# (.Net), and they have been working fine for the most part. Recently someone reported that ipon occassion (originally rarely, but more frequently on some systems of late), there is an entry in the Event Log immediately after a boot indicating that the service failed to start after 30,000 milliseconds. Usually it starts fine when attempting manually after the boot.

I instrumented the code to write entries to the Event Log during its main() execution as well as during the OnStart() execution -- but when it fails, there are no entries in the Event Log from the service code!

Attempting to launch the service as a console application always seems to succeed. Interestingly, launching as a console application is about 10 times faster than starting the service! In no case that the service loaded properly did the time pass the 500 milliseond duration!

I checked and there are no dependencies marked for the service. Is it possible that .Net is not available at that time and the service cannot execute?

How can I define any dependencies at compile time? The ServiceInstaller permits me to define a list of services to depend on, but there does not seem to be any dependency on other objects. Nor does there appear to be any .Net service on which I could wait.

Does anyone have any ideas on why my service may be failing to load, but only at boot time?

Where does the /LogToConsole=false switch setting come from on my installed services? How do I change this to true, and what effect would that have on my service?

-ken
.



Relevant Pages

  • Erroneous Compile Errors
    ... A lot of times after making various changes to one of the VB files in one of the projects, the Build fails. ... I switch the solution configuration to the other configuration (release to debug A0471001 or debug A0471001 to release) and the Build succeeds. ...
    (microsoft.public.vsnet.general)
  • Re: .Net (C#) Service Fails To Start
    ... One technique you could try if all else fails is to insert a try/catch block ... > mainexecution as well as during the OnStart() execution -- but when it ... > I checked and there are no dependencies marked for the service. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Program crashes when running it outside dev environment
    ... If I try to launch the debug on the ... crashing program, it'll close before the debugger opens. ... If it just fails strangely and sometimes inside system functions it might be overwritten memory or some such problem. ... Put one of those lines immediately before the line that crashes the program. ...
    (comp.lang.c)
  • Re: Strange fopen error
    ... First time I open the file with fopen, it succeeds. ... file, it fails. ...   if{ ... I guess it's the glfw lib that changes the working directory. ...
    (comp.sys.mac.programmer.help)
  • Re: renaming a table
    ... > if it succeeds, truncate all rows in your target rable, copy the inbox rows ... If I do that and the download fails for some reason, ...
    (microsoft.public.sqlserver.ce)