By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,601 Members | 1,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,601 IT Pros & Developers. It's quick & easy.

Gracefully kill a console app?

P: n/a
Is there such a thing as a Windows standard for killing a console app that
is monitored by a System.Diagnostics.Process object?

I'm hosting several C# console apps in a C# Windows service and would like
to standardize on a graceful termination method when the Windows service
stops.

Jon
Nov 27 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Jon,

Here are a couple ideas that may or may not work for you, depending on your
application, which are probably much more graceful than a Kill on the
process. You have two separate processes and will need to get them to
communicate somehow. You could add a Cancel property to your console
application and have it check that property periodically. Then use Remoting
to allow the service to set that Cancel property.

Another potential option is to use WCF. You can have the console
applications host their own Web Service and then make the Windows Service
call the console Web Service, which would set the Cancel property.

I don't know if this will work for you, but maybe it is something you can use.

Joe
--
http://www.csharp-station.com
"Jon Davis" wrote:
Is there such a thing as a Windows standard for killing a console app that
is monitored by a System.Diagnostics.Process object?

I'm hosting several C# console apps in a C# Windows service and would like
to standardize on a graceful termination method when the Windows service
stops.

Jon
Nov 27 '06 #2

P: n/a
So there isn't a standard Win32 "Exit Requested" signal for console apps.

Thanks.

Jon
"Joe Mayo (C# MVP)" <Jo*********@discussions.microsoft.comwrote in message
news:37**********************************@microsof t.com...
Hi Jon,

Here are a couple ideas that may or may not work for you, depending on
your
application, which are probably much more graceful than a Kill on the
process. You have two separate processes and will need to get them to
communicate somehow. You could add a Cancel property to your console
application and have it check that property periodically. Then use
Remoting
to allow the service to set that Cancel property.

Another potential option is to use WCF. You can have the console
applications host their own Web Service and then make the Windows Service
call the console Web Service, which would set the Cancel property.

I don't know if this will work for you, but maybe it is something you can
use.

Joe
--
http://www.csharp-station.com
"Jon Davis" wrote:
>Is there such a thing as a Windows standard for killing a console app
that
is monitored by a System.Diagnostics.Process object?

I'm hosting several C# console apps in a C# Windows service and would
like
to standardize on a graceful termination method when the Windows service
stops.

Jon
Nov 28 '06 #3

P: n/a
"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.netwrote in message
news:en**************@TK2MSFTNGP04.phx.gbl...
So there isn't a standard Win32 "Exit Requested" signal for console apps.

Thanks.

Jon
The closest you can get is by sending a CTRL+C to the console application's stdin, of course
this requires you to redirect the stdin and register a CTRL+C handler in the console
application.

Willy.

Nov 28 '06 #4

P: n/a
Jon Davis wrote:
So there isn't a standard Win32 "Exit Requested" signal for console
apps.
In an earlier project (a couple of years ago and not .NET) I looked very
hard for exactly that. If there is a way, it is undocumented.

So I ended up killing them, no questions asked.

Ebbe
Nov 28 '06 #5

P: n/a
"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.netwrote:
>Is there such a thing as a Windows standard for killing a console app that
is monitored by a System.Diagnostics.Process object?
I'm hosting several C# console apps in a C# Windows service and would like
to standardize on a graceful termination method when the Windows service
stops.
In addition to the other ideas in this thread: some console apps
terminate themselves naturally when they encounter an EOF on their
STDIN. So you could provide STDIN yourself through a pipe, and close
it when it's time. (it's not a standardized way: it'll be different
for each app.)

--
Lu
Nov 28 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.