Troubleshooting a sporadically dying Windows service written in C#

10 views
Skip to first unread message

Anton Shepelev

unread,
May 8, 2019, 7:31:07 AM5/8/19
to
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

unread,
May 11, 2019, 9:28:47 PM5/11/19
to
On 5/8/2019 7:31 AM, Anton Shepelev wrote:
> 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

unread,
May 12, 2019, 2:57:43 AM5/12/19
to
Am 08.05.19 um 13:31 schrieb 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

unread,
Sep 11, 2020, 1:13:15 PM9/11/20
to
I wrote:

> 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.

Marcel Mueller:

> There are two exceptions that can't be handled gracefully:
> - 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?

> An of course unmanaged code may always cause crashes as
> well.

Our service uses COM-objects, so that is another possiblity.

> 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.

> 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
Reply all
Reply to author
Forward
0 new messages