Windows Service and shutdown/restart of server...

T

Tom

I've written a Windows Service using VB.NET, which does a
connection to a database and then runs a timer to
periodically process some data. It is running pretty well;
However, I have noticed one issue: Whenever the
workstation/server is shut down/restarted the database
connection is staying open. It is as though the Windows
Service Manager is not calling the STOP method for my
service whenever the server is shutting down. Is there
something else I need to code for (i.e. the
OnPowerShutdown) to make sure my service 'stops' whenever
the machine is shut down?

Thanks in advance.

Tom
--
 
K

Kevin Spencer

Have you implemented an OnShutDown event handler for the service? If you do,
you should set CanShutDown to true as well.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Big things are made up of
lots of little things.
 
T

Tom

Kevin said:
Have you implemented an OnShutDown event handler for the
service? If you do, you should set CanShutDown to true as
well.

Ah, stupid me, that is what I am missing. Duh, didn't code
the OnShutdown event...

Thanks!

--
 
T

Tom

Kevin said:
Have you implemented an OnShutDown event handler for the
service? If you do, you should set CanShutDown to true as
well.

Kevin: I take my previous message back... I coded the
appropriate stuff into the OnShutdown event. The last
statement I have in there is one to write to the log that
the service was successfully shut down. I even have the
CanShutdown = True up in the constructor.

However, if I restart or shutdown my server (and the
service is running) it still doesn't seem to run the
OnShutdown method. I know this to be true because (1) I
never get the shutdown message in the application log, and
(2) My database connection is still left open!

Any ideas as to what else I need to look or code for?
Thanks.

Tom

--
 
K

Kevin Spencer

I'm pretty much out of ideas at this point. You could try writing a
deconstructor or Dispose method.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Big things are made up of
lots of little things.
 
W

Willy Denoyette [MVP]

Are you sure the eventlog service is still running when your OnShutdown
handler runs?
Better write to a logfile.

Willy.
 

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