473,414 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Gracefully kill a console app?

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
5 8353
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
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
"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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: KB | last post by:
Hi, I want to write a Python script that controls and automates a Windows GUI computation program. My problem is that I do not know how to quit the Windows GUI program gracefully with a...
2
by: Jerry | last post by:
If a Windows User decides to kill a process or a separate Windows app calls Process.Kill(), is there any way that the process being killed can see what's going on before it dies? I have a Windows...
7
by: Andrew S. Giles | last post by:
Hello, I am looking for an article, or some information about how to get a C# windows forms application to trap the "End Process" event from the Task Manager? Is such a thing possible, and if...
7
by: yaron | last post by:
Hi, I am looking for doing this : void OnKillProcess() { do Cleanup; } i don't want to use ~MyClass() (or Finalize), because i wan't that
7
by: Joe | last post by:
If I'm using process.kill, I can only kill processes, which are created in the same login session. (I'm using win2000, I'm in the local admin group) Processes created by me in earlier logins or...
7
by: Frank | last post by:
Hi, I have a console app that I want to stop gracefully by another program. The console app already has code to intercept control-c and logoff and so on. But how do I send a control-c to that...
2
by: Poly-poly man | last post by:
I am working on a GTK Midi player (timidgtk.sourceforge.net). As you can see, it's just a timidity frontend. With version 0.03, I'm trying to devel it to use SDL_sound to play the midis. First...
1
by: =?Utf-8?B?RGF2ZSBCb29rZXI=?= | last post by:
How can I kill or close a MessageBox that is shown in a thread that I later abort? In the following code, the MessageBox will always stay open until closed by the user, even when the other event...
4
!NoItAll
by: !NoItAll | last post by:
I have a program that needs to access the files that are open by another program on the computer. When my application comes up I can easily see if the other application is running with the .net...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.