Connecting Tech Pros Worldwide Forums | Help | Site Map

Gracefully kill a console app?

Jon Davis
Guest
 
Posts: n/a
#1: Nov 27 '06
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



Joe Mayo (C# MVP)
Guest
 
Posts: n/a
#2: Nov 27 '06

re: Gracefully kill a console app?


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:
Quote:
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
>
>
>
Jon Davis
Guest
 
Posts: n/a
#3: Nov 28 '06

re: Gracefully kill a console app?


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

Thanks.

Jon


"Joe Mayo (C# MVP)" <JoeMayoCMVP@discussions.microsoft.comwrote in message
news:3735B7E9-70AF-4EAC-A5B9-650AA348DCAB@microsoft.com...
Quote:
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:
>
Quote:
>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
>>
>>
>>
Willy Denoyette [MVP]
Guest
 
Posts: n/a
#4: Nov 28 '06

re: Gracefully kill a console app?


"Jon Davis" <jon@REMOVE.ME.PLEASE.jondavis.netwrote in message
news:enZULlrEHHA.4256@TK2MSFTNGP04.phx.gbl...
Quote:
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.

Ebbe Kristensen
Guest
 
Posts: n/a
#5: Nov 28 '06

re: Gracefully kill a console app?


Jon Davis wrote:
Quote:
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


Lucian Wischik
Guest
 
Posts: n/a
#6: Nov 28 '06

re: Gracefully kill a console app?


"Jon Davis" <jon@REMOVE.ME.PLEASE.jondavis.netwrote:
Quote:
>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
Closed Thread


Similar C# / C Sharp bytes