Get return value from process

C#Process

C# Problem Overview


Hi I am trying to do the following: I have a process which can take parameters (digits) and return the sum of these numbers

Process P = Process.Start(sPhysicalFilePath, Param);
                int result = P.ExitCode;

I get the return value from "ExitCode" the problem is: the program sometimes finishes his work before the process so when the program reaches this line

int result = P.ExitCode;

I got an exception .. my question is how to wait this process until it finishes its work sorry I forget to say that's I am working with C# language

C# Solutions


Solution 1 - C#

use:

Process P = Process.Start(sPhysicalFilePath, Param);
P.WaitForExit();
int result = P.ExitCode;

from MSDN

Solution 2 - C#

You can try the below code:

    Dim P As New Process
    P = Process.Start(info)
    P.WaitForExit()
    fichiersATraiter = P.ExitCode

Hope this helps :)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHanyView Question on Stackoverflow
Solution 1 - C#snickerView Answer on Stackoverflow
Solution 2 - C#Bahaa J.View Answer on Stackoverflow