When your program is being exited write a function to kill the running process
//pseudo code
OnExit()
{
if process is running, kill it
}
Main Topics
Browse All TopicsI have created a console application. In this application, i spawn a new process using Process.Start()
ie,
main{
...
...
Process.Start(Program1.exe
...
...
}
Now, i need to stop the spawned process once the actual parent program is stopped. The stoppage could be the actual end of the program or the user could just press Control-C. Eitherways, the spawned program needs to abort. How do i do it??
Regards.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Greg,
My problem is not with the kill method. How do I call the Kill method when the Main program terminates. ie., the main program need not terminate gracefully. The user can also send a Control C interrupt from the command prompt. Whatever be the reason why the main program is terminating, the spawned program should also stop.
Mail2Dolly,
Does such a method called OnExit exist in C#??
Vikkki
http://msdn.microsoft.com/
Business Accounts
Answer for Membership
by: gregoryyoungPosted on 2004-05-19 at 14:20:21ID: 11112170
Process p = Process.Start(Program1)
library/en -us/cpref/ html/ frlrf systemdiag nosticspro cessclassh asexitedto pic.asp hasexited library/en -us/cpref/ html/ frlrf systemdiag nosticspro cessclassk illtopic.a sp kill
if(!p.HasExited) {
p.Kill()
}
the kill methods kills the other app immediately it cannot cancel this.
relevant MSDN
http://msdn.microsoft.com/
http://msdn.microsoft.com/
Cheers,
Greg