Service Crashing

  • Thread starter Thread starter Cuong Tong
  • Start date Start date
C

Cuong Tong

I ran my service and it crashes everynow and then. The following log is recoreded
in the Application Event viewer

An unhandled win32 exception occurred in XYZService.exe [9204]. Just-In-Time
debugging this exception failed with the following error: Debugger could
not be started because no user is logged on.

Has anyone got any comments?
 
Hi,
Has anyone got any comments?

Yes,...

Try to debug your service or wrap critical code segments
into a try-catch block and try to find out what makes this
that bad. See here for some VB Example (not different from
C#)

http://www.ondotnet.com/pub/a/dotnet/2003/09/02/debuggingsvcs.html

You also can post some code here, so that we can
have a look at your code,...

I could not find some error code on my system with "9204".
You can try, maybe you will have that code. Check out
my little Exception Viewer if you like:
http://entwicklung.junetz.de/projects/opensource/WindowsExceptionViewer/WindowsExceptionViewer.zip

But best would be some code here,...


Regards

Kerem


--
 
...or wrap critical code segments into a try-catch block...

Just to observe that the most pragmatic approach here may actually be
to wrap your main work method[*] in a try/catch, doing some error-
logging in the "catch" (perhaps simply writing the message,
stacktrace, etc to the event-log). I agree that exception handling
(esp. "finally") should be "where necessary" in the code, but this
isn't often a useful debugging tool unless you get lucky.

[*]=since tihs is a service, I'm assuming that you spin up a thread in
the "start"; I mean the method you used for the delegate to start the
thread.

Marc
 
Oh - and any other thread you start ;-p

Any thread that exits because of an unhandled exception will break
your app; this is a good thing as it almost certainly indicates
instability. If you are using lots of threading, perhaps add your
error-logging method to AppDomain.UnhandledException (noting that
ExceptionObject will almost certainly be an Exception).

A very crude (and untested) implementation is shown below. Note that
you might need your installer to create the named ("MyService") event-
source, otherwise this could iteslf explode.

AppDomain.CurrentDomain.UnhandledException +=
CurrentDomain_UnhandledException;
....
static void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e) {
Exception ex = e.ExceptionObject as Exception;
if (ex == null) {
string msg; // try to log whatever the heck happened!
try { msg = e.ExceptionObject.ToString(); }
catch { msg = "(unreadable exception)"; }
EventLog.WriteEntry("MyService", msg,
EventLogEntryType.Error);
} else {
// log outermost message and stack-trace
EventLog.WriteEntry("MyService", ex.Message,
EventLogEntryType.Error);
EventLog.WriteEntry("MyService", ex.StackTrace,
EventLogEntryType.Information);
while ((ex = ex.InnerException) != null) { // log
inner exception messages
EventLog.WriteEntry("MyService", ex.Message,
EventLogEntryType.Information);
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top