Debugging Windows Service on Test Machine?

A

Andrew Raastad

I have a real brain buster here... In a previous post I was having some
issue getting this Windows Service installed, but that is resolved now. The
problem I have now is that the Service "stops unexpectedly" without any
errors or exceptions thrown on our 64bit test server (WinServer2008 R2) -
this Windows Service functions perfectly on our 32bit servers (2003/2008).
It starts, runs for about 5 or so seconds, then stops, and the only error is
in the System Event Log: "The [service] terminated unexpectedly. It has done
this [X] times."

The Service is pretty straight forward, relatively light in code, which is
why this is such a pain in the butt to figure out.... not to mention it's
doing it on a non-development machine, and I have no clue how to debug it
'over there'.

The Service is a Visual Studio 2008 Windows Service Project, which has a
ServiceStarter.vb component (the OnStart and OnStop handlers), and a
Worker.vb component. The OnStart handler of ServiceStarter instatiates a new
thread, sets the ThreadStart property to the main function of the Worker
component (DoWork()), and starts the thread. The DoWork() method is a loop
that calls an internal function, and then does a Thread.Sleep for 10 seconds
before looping again. All pretty standard.

However, the Service "terminates unexpectedly" just before the internal
method call of DoWork(). I know this because I added a method that writes
an entry into the Event Log (basically a version of the old debug.print("Got
to here") statement) and called it at each step along the way of the process
chain. What I get is this (going top down, in custom event log):

[2/2/2010 12:01 PM]: [Service]: NPInterface Service Started - 2/2/2010
12:01:39 PM
[2/2/2010 12:01 PM]: [Worker Process]: DoWork() Begun - 2/2/2010 12:01:39 PM
[2/2/2010 12:01 PM]: [Worker Process]: Entering DoWork() Loop - 2/2/2010
12:01:39 PM
[2/2/2010 12:01 PM]: [Worker Process]: Executing ExchangeSchedule() -
2/2/2010 12:01:39 PM

followed by this in the System Event log:

"The [Service] service terminated unexpectedly. It has done this [X]
time(s)." [2/2/2010 12:01:56 PM]

Here is the code of the Worker.vb component relavent to the above:

Public Sub DoWork()
WriteEvent(String.Format("DoWork() Begun - {0}", Now),
EventLogEntryType.Information)

' This loop is set up to run indefinitely
While Not MustStop
WriteEvent(String.Format("Entering DoWork() Loop - {0}", Now),
EventLogEntryType.Information)
Try
' Process any information waiting on the Cache system
WriteEvent(String.Format("Executing ExchangeSchedule() -
{0}", Now), EventLogEntryType.Information)
ExchangeSchedule()
WriteEvent(String.Format("ExchangeSchedule() Completed -
{0}", Now), EventLogEntryType.Information)

And the beginning of the ExchangeSchedule() method:

Private Sub ExchangeSchedule()
WriteEvent(String.Format("Inside and beginning ExchangeSchedule()
method - {0}", Now), EventLogEntryType.Information)
Try

So, you can see that if ExchangeSchedule() exectued, the very first thing it
would do is make another entry. But from the log file, that never happened.
The Service just stops, mid-process, mid-loop, no error, no exceptions, no
reason that I can discover. And the fact I cannot reproduce this problem
anywhere else is making this a real b!tch to figure out.

Help, anyone??

-- Andrew
 
P

Phill W.

Try
' Process any information waiting on the Cache system
WriteEvent(String.Format("Executing ExchangeSchedule() - {0}", Now),
EventLogEntryType.Information)
ExchangeSchedule()
WriteEvent(String.Format("ExchangeSchedule() Completed - {0}", Now),
EventLogEntryType.Information)

And the beginning of the ExchangeSchedule() method:

Private Sub ExchangeSchedule()
WriteEvent(String.Format("Inside and beginning ExchangeSchedule() method
- {0}", Now), EventLogEntryType.Information)
Try

So, you can see that if ExchangeSchedule() executed, the very first
thing it would do is make another entry. But from the log file, that
never happened. The Service just stops, mid-process, mid-loop, no error,
no exceptions, no reason that I can discover.

What Types does ExecuteSchedule make use of?

I'm guessing it's declaring or instantiating an object of a Type that
you haven't used anywhere else and you're getting a TypeLoadException
thrown out of that.
I had a similar problem driving a Windows Service with a Timer - the
Timer event handler used a "new" Type which failed to load and hence
threw a TypeLoadException (not that I could ever find anywhere that it
had been caught!) and the routine /simply didn't run/.

It looks like you've got a Try .. Catch construct in there already -
what Type of Exception are you catching? At this stage,
System.Exception is your only option.

Also, check if the Event Log File is full - believe it or not, I've seen
some /very/ strange circumstances where this can cause a Service to
disappear without trace.

HTH,
Phill W.
 
A

Andrew Raastad

Thansk Phill for the reponse. In some more checking I found that there was
a DLL missing that should have been in the application folder (an issue for
which I need to look at the installer project again...) but even after I
copied the DLL into the folder and restarted the Service... still same end
result but now just in a different location.

I have visually verified all needed files/dependancies are in place. I
double checked that all other resources, a valid url for a web reference,
etc. all are correct. But the thing still just quits with no errors or
exceptions. I have litterally every method, sub, function, all wrapped in
Try...Catch Blocks, yet even still the thing stops without so much as a
peep. I should see some error generated in the logs, something. Nope. The
service starts, runs for a few seconds, cheerfully logging the checkpoints
in the log file I marked, and then stop, no errors, nothing... *poof*

As for your question about what Types doe ExecutSchedule() make use of...
There is a separate class, Integration.vb, which has a Web Reference to a
remote database, and a reference to a class "webdavex.dll" which is a
utility for interfacing with Exchange
(http://www.independentsoft.de/webdavex/index.html).

For the sheer hell of it, I rewrote the service as a Winforms app, which has
all the same functionality and processing steps as the Service, but this one
starts when I click a button, and prints the 'checkpoints' to a listbox on
the form so I can see it functioning in real-time. And guess what? No
problems, no unexpected stops, it trucks right along doing what it is
supposed to.

Now why the world is it working just fine as a WinForms app, but
unexpectedly terminates (without errors) when it's a Service??

Anyone?

-- Andrew
 

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

Top