-1

currently my application is on .net framework 4.8 using this I need to run a .exe file which is in .net 6.

 System.Diagnostics.Process newProcess = null;
        try
        {
            // create application
            ProcessStartInfo procInfo = new ProcessStartInfo
            {
                FileName = "<path of the .exe file>",
                Arguments = arguments,
                CreateNoWindow = false,
                UseShellExecute = true,
                WindowStyle = ProcessWindowStyle.Hidden,
                WorkingDirectory = Path.GetTempPath()
            };


newProcess = new Process
            {
                StartInfo = procInfo,
                EnableRaisingEvents = true
            };

 // now start the process
            newProcess.Start();
            newProcess.PriorityClass = ProcessPriorityClass.High;
            started = true;

But after last line when I check this

System.Diagnostics.Process.GetProcessById(newProcess.Id)

i am getting an exceptionenter image description here

1 Answers1

0
            newProcess.PriorityClass = ProcessPriorityClass.High;

Wrap this in a try/catch. The process died trying to start.

Now then; if the process dies so early newProcess.ExitCode will be a HRESULT of the failure to start the process (or rarely an NT error code).

If it's an unexpected zero and the process didn't do anything, blame antivirus.

System.Diagnostics.Process.GetProcessById(newProcess.Id)

But whyyyyy? Looks like you want newProcess.Refresh().

Joshua
  • 40,822
  • 8
  • 72
  • 132
  • actually this Line System.Diagnostics.Process.GetProcessById(newProcess.Id) i am using in immediate window to see if the process is running or not . – Aditya Dalai Aug 28 '22 at 03:34
  • @Adityadalai: Doesn't matter. You need the exit code to make progress. – Joshua Aug 28 '22 at 04:07
  • but the samething is working when I tried it for a .net framemework 4.8 .exe file , but after migrate that console app it into .net 6 it failes , is it a compatable issue ? – Aditya Dalai Aug 28 '22 at 05:00
  • @Adityadalai: No. It's a you messed something up issue without a whole lot of useful details. – Joshua Aug 28 '22 at 14:20