5

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
  • 7,168
  • 9
  • 31
  • 54
77vetter
  • 143
  • 1
  • 7

2 Answers2

2

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
  • 7,168
  • 9
  • 31
  • 54
Hans Karlsen
  • 2,117
  • 1
  • 13
  • 15
0
Process.Start("TheNameOfTheOtherProcess.exe");
Servy
  • 197,813
  • 25
  • 319
  • 428
  • 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