8

I need to start a process from a C# console app and then allow the console app to finish/end without waiting for the process/thread to finish.

How do I do this?

janw
  • 8,758
  • 11
  • 40
  • 62
77vetter
  • 173
  • 1
  • 7

2 Answers2

7

You need to avoid making your new process a child process of the current process:

ProcessStartInfo sinfo = new ProcessStartInfo();
sinfo.UseShellExecute = true; // Do not wait - make the process stand alone
sinfo.FileName = "PathAndNameofExe";
Process.Start(sinfo);
janw
  • 8,758
  • 11
  • 40
  • 62
Hans Karlsen
  • 2,275
  • 1
  • 15
  • 15
0
Process.Start("TheNameOfTheOtherProcess.exe");
Servy
  • 202,030
  • 26
  • 332
  • 449
  • 1
    This only works on .NET Framework apps, where the default is to use ShellExecute. In Core UseShellExecute defaults to false. Please see the answer from @hans-karlsen for a solution that works in both. – Nanki Nov 09 '21 at 12:37
  • @Nanki I mean sure, this doesn't apply to technologies that were created years after this question or answer were posted. You seem to think that this question is a different question than the one that is actually is. – Servy Nov 09 '21 at 16:32
  • 1
    Not at all. Your answer was perfect at the time, it's just been superceded. – Nanki Nov 09 '21 at 23:17