Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I'm bulding a c# application who make some operation and start one or more external application
with

C#
string pathMyApp = ......external executable
ProcessStartInfo startInfo = new ProcessStartInfo() { FileName = "pathMyApp", Arguments = ......someAppParameter, };
proc = new Process() { StartInfo = startInfo, };
proc.Start()


It's all Ok but after external process start the main app continue to end and when it finish all process ends too.

Is it possible to close my mainApp and continue executing of child app?


Now i've putted a readkey at the end of main application to prevent the end but it's not good.
have any solution?
thank's

What I have tried:

C#
I've tried with
<pre lang="C#">ThreadStart ths = new ThreadStart(() =&gt; proc.Start());
           Thread th = new Thread(ths);
           th.Start();</pre>

too, but is the same.
Posted
Updated 6-Oct-16 6:56am
Comments
Rob Philpott 6-Oct-16 12:05pm    
This has me confused. What you describe doesn't match what I understood happens, and indeed when I write a simple console app which launches Notepad, Notepad stays when the console app dies.

The processes you are trying to start, what are they? Console/Windows/Services?
[no name] 6-Oct-16 12:06pm    
Haven't tested it but you might try UseShellExecute = true

1 solution

Processes and Threads are different in one important respect: when your application closes, all it's thread are closed as well provided they are marked as "background" - if they aren't, then they persist even once the app itself is closed. The only way to override that is to call Environment.Exit instead of Application.Exit, as that terminates all running threads associated with the app regardless of their background status.
Processes always survive the application - they are independant of the app and are not terminated automatically.

I suspect you need to look at your code again, as I dont; think it operates teh way you think it is!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900