我正在运行一个统一的进程,需要一些时间(实际上可能需要30分钟),但是我希望统一运行它最多5分钟如果没有输出,则返回。 我也想在这个等待5分钟的时间里展示这样的东西如何在Unity3d中运行进程时执行某些操作
任何人都有一个想法如何做到这一点?我试着用这行代码
myProcess.WaitForExit(1000 * 60 * 5);
,但我不能做任何事情,而它的等待,我想这是我阻止或东西,任何人可以帮助?
编辑:
public void onClickFindSol(){
paused=true;
ReadRedFace();
ReadGreenFace();
ReadBlueFace();
ReadYellowFace();
ReadOrangeFace();
ReadWhiteFace();
if (File.Exists (path))
File.Delete (path);
System.IO.File.WriteAllText(path,InputToAlgo);
myProcess = new Process();
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.FileName = (System.Environment.CurrentDirectory)+Path.DirectorySeparatorChar+"rubik3Sticker.ida2";
myProcess.EnableRaisingEvents = true;
myProcess.StartInfo.WorkingDirectory = (System.Environment.CurrentDirectory)+Path.DirectorySeparatorChar;
myProcess.StartInfo.Arguments = "corner.bin edge1.bin edge2.bin";
myProcess.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
{
if (!String.IsNullOrEmpty(e.Data)){
timer = 0f;
StepsOfSolution++;
print(e.Data);
solution.output.Add(e.Data);
}
});
myProcess.Start();
myProcess.BeginOutputReadLine();
}
void Update(){
if (myProcess != null){
if(timer>fiveMinutes){
myProcess.Kill();
myProcess.Close();
badExit=true;
myProcess=null;
return;
}
timer += Time.deltaTime;
if (!myProcess.HasExited){
RubikScene.PleaseWait.SetActive(true);
}
else{
if(badExit){
RubikScene.PleaseWait.SetActive(false);
RubikScene.TooLong.SetActive(true);
print("TimeOut!");
}else{
paused=false;
Application.LoadLevel("solution");
}
}
}
}
使输出定时检查每X秒,而计时器不超过5分钟,如果它然后停止的过程中,没有必要阻止任何东西 –
@ user2320445 WaitForExit阻止一切。 – Programmer