Discussion:
Troubleshooting a sporadically dying Windows service written in C#
(too old to reply)
Anton Shepelev
2019-05-08 11:31:00 UTC
Permalink
Hello, all

I have a singel-threaded Windows service in C#. Its main
loop is wrapped in a `try' block, and I am logging the
exception the `catch' block. I have also subscribed to

AppDomain.CurrentDomain.UnhandledException

and am logging it too, as well the Start and Stop commands.
Yet my client reports that sometimes my service stops
without writing anything in the log. What can be the cause
if the log file is accessible (the service adds an entry at
start-up) and nobody is stopping the service process via
Task manager (I belive them they don't)? How can I diagnose
the situation?
--
() ascii ribbon campaign - against html e-mail
/\ http://preview.tinyurl.com/qcy6mjc [archived]
Arne Vajhøj
2019-05-12 01:28:40 UTC
Permalink
Post by Anton Shepelev
I have a singel-threaded Windows service in C#. Its main
loop is wrapped in a `try' block, and I am logging the
exception the `catch' block. I have also subscribed to
AppDomain.CurrentDomain.UnhandledException
and am logging it too, as well the Start and Stop commands.
Yet my client reports that sometimes my service stops
without writing anything in the log. What can be the cause
if the log file is accessible (the service adds an entry at
start-up) and nobody is stopping the service process via
Task manager (I belive them they don't)? How can I diagnose
the situation?
Any chance that the application is running out of memory?

Any native code involved?

Anyway - difficult scenario.

I would suggest extensive trace logging to try and determine
where it stops.

Arne
Marcel Mueller
2019-05-12 06:57:39 UTC
Permalink
Post by Anton Shepelev
Yet my client reports that sometimes my service stops
without writing anything in the log.
There are two exceptions that can't be handled gracefully:
- out of memory and
- stack overflow.
An of course unmanaged code may always cause crashes as well.
There is also a small chance that race conditions crash the entire
application. Even if your service is single threaded AFAIK this does not
apply to SCM events.

Have a look at the system logfiles. Unhandled program terminations are
usually logged there.


Marcel
Anton Shepelev
2020-09-11 17:13:04 UTC
Permalink
Post by Anton Shepelev
I have a singel-threaded Windows service in C#. Its main
loop is wrapped in a `try' block, and I am logging the
exception the `catch' block. I have also subscribed to
AppDomain.CurrentDomain.UnhandledException
and am logging it too, as well the Start and Stop
commands. Yet my client reports that sometimes my service
stops without writing anything in the log. What can be
the cause if the log file is accessible (the service adds
an entry at start-up) and nobody is stopping the service
process via Task manager (I belive them they don't)? How
can I diagnose the situation?
After more than a year, I am back at it.
Post by Anton Shepelev
- out of memory and
- stack overflow.
Understandable, but I don't think either of them happened.
And if it did, is there a standard Windows or .NET facility
that can detect and log those exceptions, or preferably any
unhandled exceptions in any .NET application?
Post by Anton Shepelev
An of course unmanaged code may always cause crashes as
well.
Our service uses COM-objects, so that is another possiblity.
Post by Anton Shepelev
There is also a small chance that race conditions crash
the entire application. Even if your service is single
threaded AFAIK this does not apply to SCM events.
Yes, mine is a single-threaded service (KISS). Do you mean
a race condition related to the service's handling of a
command sent via SCM? I am logging all the events that my
service handles, which are only two: OnStart() and OnStop().
Yet nothing appears in the log after abnormal terminations.
Post by Anton Shepelev
Have a look at the system logfiles. Unhandled program
terminations are usually logged there.
All I have found is entries in the event Journal saying that
the service terminated unexpectedly.

Has anybody used ADPlus -- a Visual Basic script that
facilitates the troubleshooting of handing or crashing
programs:

https://support.microsoft.com/en-us/help/286350/how-to-use-adplus-vbs-to-troubleshoot-hangs-and-crashes
--
() ascii ribbon campaign - against html e-mail
/\ http://preview.tinyurl.com/qcy6mjc [archived]
Loading...