获得过程的返回值 [英] Get return value from process

查看:78
本文介绍了获得过程的返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我试图做到以下几点:
我有一个过程,可以带参数(位)
并返回这些数的总和

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;

我从退出code的返回值
问题是:
程序有时完成他的工作过程之前
因此,当程序运行到这一行

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;

我得到了一个异常..
我的问题是如何,直到它完成其工作等待这个过程
抱歉,我忘了说是我用C#语言的工作

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

推荐答案

使用:

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

从<一个href=\"http://msdn.microsoft.com/en-us/library/system.diagnostics.process.waitforexit.aspx\">MSDN

这篇关于获得过程的返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆