0

I'm wondering is it possible to start sort of a background process with Process.Start? If I use Process.Start it starts a new process, thus the process is independent of the original process as far as I understand:

ProcessStartInfo processInfo = new ProcessStartInfo(fileToBeExecuted);
processInfo.UseShellExecute = true;
Process.Start(processInfo);

Now my question is is it possible to use Process.Start to start a background process for the original process without resorting to interprocess communication to end it?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Thomas
  • 2,886
  • 3
  • 34
  • 78
  • A "background process" is just a process, so you're still left with the question how to inform the other process that it needs to exit. Why do you need to start a background process, as opposed to just implementing the code needed in your main application? In other words, why do you need to split it into two processes in the first place? – Lasse V. Karlsen Sep 12 '14 at 06:58
  • You could create the process in a background worker? – Sayse Sep 12 '14 at 06:59
  • @Sayse Yes he could, but that wouldn't make the process more of a "background process" than it already is. It would allow you to wait for that process to exit without blocking the UI, but the other process wouldn't be different in any way because of it. – Lasse V. Karlsen Sep 12 '14 at 07:00
  • @LasseV.Karlsen - Agreed, but my thinking was there wouldn't be any need to explicitly state it as a background process unless you intend for it to return (where you need to wait for its return) – Sayse Sep 12 '14 at 07:01
  • What does inter process comunication have to do here ? – Tigran Sep 12 '14 at 07:02
  • 1
    Is your question how to kill child process when parent dies? You may get answer [here](http://stackoverflow.com/questions/15206516/killing-external-process-when-application-dies) – Sriram Sakthivel Sep 12 '14 at 07:03
  • @SriramSakthivel I think he's trying to create a process hierarchy inside his application so it automatically dies when the parent dies. – Yuval Itzchakov Sep 12 '14 at 07:11
  • @YuvalItzchakov Question I linked has the answer to that question, I suppose. – Sriram Sakthivel Sep 12 '14 at 07:12
  • YuvalItzchakov has it correct there. I'm regularly using backgorund and foregrond threads inside of applicaitons and wondered if there is a way to automatically link "child" processes in a way that is similar to how threads function there. Thus when the parent dies the child dies automatically without one having to program out a complete inter process communication (like a named pipe which the child checks if the parent sends a kill signal) oneself. – Thomas Sep 12 '14 at 07:14
  • You dont get this automatically when starting a new process inside your application. But you can definitely use [this](http://stackoverflow.com/questions/3342941/kill-child-process-when-parent-process-is-killed) to signal your child processes when the parent dies. – Yuval Itzchakov Sep 12 '14 at 07:16
  • @SriramSakthivel - I have no idea how you managed to decipher that was a duplicate but kudos – Sayse Sep 12 '14 at 07:41
  • 1
    @Sayse Ha ha, *interprocess communication* is the key which made me to understand what OP is talking about. Typically we use IPC to ask another process to shutdown :) – Sriram Sakthivel Sep 12 '14 at 07:43
  • Good work there for finding it!. I didn't see that one question when I had searched if there is an existing solution to the problem – Thomas Sep 12 '14 at 08:07

0 Answers0