C# process 执行exe文件 死循环问题

我用tcc命令编译生成xx.c文件在执行时若.c文件里面有死循环如何结束?如何获取其运行时间?代码如下stringfileName=this.compiler+probl... 我用tcc命令编译生成xx.c文件 在执行时若.c文件里面有死循环如何结束?
如何获取其运行时间?代码如下
string fileName = this.compiler + problemId + userName + ".exe";
StreamReader sr = File.OpenText(this.judgeIn + problemId + ".in");
string test = sr.ReadToEnd();
sr.Close();
this.p.StartInfo.CreateNoWindow = false;
this.p.StartInfo.UseShellExecute = false;
this.p.StartInfo.FileName = fileName;
this.p.StartInfo.RedirectStandardError = true;
this.p.StartInfo.RedirectStandardInput = true;
this.p.StartInfo.RedirectStandardOutput = true;
Timer timer = new Timer();
timer.Interval = Convert.ToDouble(time);//设置timer间隔
timer.Enabled = true;
timer.AutoReset = false;
this.p.Start();
timer.Start();
this.p.StandardInput.Write(test + '\n');
// string message = this.process.StandardError.ReadToEnd();
string output = this.p.StandardOutput.ReadToEnd();
this.p.WaitForExit();
TimeSpan ts = new TimeSpan();
ts = this.p.ExitTime - this.p.StartTime;//此处报错 句柄无效
this.p.Close();
timer.Stop();
return output;
展开
 我来答
百度网友d1855349d
2010-05-06 · TA获得超过430个赞
知道小有建树答主
回答量:425
采纳率:0%
帮助的人:0
展开全部
这样改:
string fileName = this.compiler + problemId + userName + ".exe";
StreamReader sr = File.OpenText(this.judgeIn + problemId + ".in");
string test = sr.ReadToEnd();
sr.Close();
DateTime startt = DateTime.Now;
this.p.StartInfo.CreateNoWindow = false;
this.p.StartInfo.UseShellExecute = false;
this.p.StartInfo.FileName = fileName;
this.p.StartInfo.RedirectStandardError = true;
this.p.StartInfo.RedirectStandardInput = true;
this.p.StartInfo.RedirectStandardOutput = true;
Timer timer = new Timer();
timer.Interval = Convert.ToDouble(time);//设置timer间隔
timer.Enabled = true;
timer.AutoReset = false;
this.p.Start();
timer.Start();
this.p.StandardInput.Write(test + '\n');
// string message = this.process.StandardError.ReadToEnd();
string output = this.p.StandardOutput.ReadToEnd();
this.p.WaitForExit();
TimeSpan ts = new TimeSpan();
ts = startt - DateTime.Now;//此处报错 句柄无效
this.p.Close();
timer.Stop();
return output;
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式