我想通過C# 運行的Iperf通過CMD一切運轉時工作正常和快速 但我使用此代碼通過C#運行時:奇怪的行爲在運行過程中使用過程類VS CMD C#
public void RunProcess(string FileName, string Arguments, bool EventWhenExit)
{
process = new Process();
process.EnableRaisingEvents = true;
process.OutputDataReceived += new DataReceivedEventHandler(OnDataReceivedEvent);
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.LoadUserProfile = false;
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = FileName; // Gets or sets the application or document to start.
process.StartInfo.Arguments =Arguments;//Gets or sets the set of command-line arguments to use when starting the application
Thread.Sleep(1000);
if (EventWhenExit)
{
process.EnableRaisingEvents = true;
process.Exited += new EventHandler(myprocess_Exited);/*New line */
}
process.Start();
process.BeginOutputReadLine();
PID = process.Id;
}
private void myprocess_Exited(object sender, EventArgs e)
{
process.Refresh();
Thread.Sleep(2000);
onProcessEnd(this, "ENDOF " + Proc.ToString());
Console.WriteLine("Process exsiting ");
}
private void OnDataReceivedEvent(object sender, DataReceivedEventArgs e)
{
string OutputFromProcess = e.Data;
//fire event to event handler class for further use
onDataOutputFromProcess(this, OutputFromProcess, Proc.ToString());
}
我得到錯誤的奇怪的行爲: 當運行1流(使用Iperf你會知道...)每一個工作正常在控制檯和我的應用程序(winform
) 但我運行3流和以上,我的應用程序不會超過,掛起時應該退出
會有什麼問題? 什麼可以很好的解決這個問題?
對於無法使用的代碼,請創建一個[MVCE](http://stackoverflow.com/help/mcve),以便我們爲您提供幫助。 – nvoigt 2014-08-28 08:58:10
我會努力:) 在意思,而你能告訴我,如果我的代碼中設置過程的方式有什麼問題嗎? – LordTitiKaka 2014-08-28 09:10:04