Service and system shutdown

A

Andy

hi all,

I've created a windows server that will watch to make sure another
process stays running. It looks for the Process and attaches to the
Exited event, which works fine.

If the program is closed, my service correctly restarts it.

The problem is that its working a bit too well, and it restarts the
application even if the system was told to shut down. Since it
respawns the application, the system seems to abort the shutdown.

How can i get the service to stop working once a shutdown is started?
I've tried setting CanShutdown = true and creating the OnShutdown(), as
well as attaching to the CurrentDomains ProcessExit event. Nether seem
to fire and the system can't be shut down until the service is stopped.

Any ideas?

Andy
 
R

Ram P. Dash

<quote>It looks for the Process and attaches to the Exited event, which
works fine.</quote>

You need to detach from the process's exited event and then close the
process on your service's OnStop method. That way, you can ensure that the
process doesn't get restarted when the service is stopping.

Ram
 
A

Andy

Ram,

I am doing that now.. i think that before Windows starts ending
services, it ends user applications. But if a user app respawns before
its done, it aborts the whole shutdown. At least thats what it seems
to be doing..

Thanks
Andy
 

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