如果您使用的是圖形用戶界面,它會停止,如果你使用WaitForExit。
這是一個異步的例子。你將不得不以使其適應您的需求:
using System;
using System.Diagnostics;
using System.ComponentModel;
using System.Threading;
class ConverterClass
{
private Process myProcess = new Process();
private bool finishedFlag = false;
/* converts a video asynchronously */
public void ConvertVideo(string fileName)
{
try
{
/* start the process */
myProcess.StartInfo.FileName = "convert.exe"; /* change this */
/* if the convert.exe app accepts one argument containing
the video file, the line below does this */
myProcess.StartInfo.Arguments = fileName;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.EnableRaisingEvents = true;
myProcess.Exited += new EventHandler(myProcess_Exited);
myProcess.Start();
}
catch (Exception ex)
{
/* handle exceptions here */
}
}
public bool finished()
{
return finishedFlag;
}
/* handle exited event (process closed) */
private void myProcess_Exited(object sender, System.EventArgs e)
{
finishedFlag = true;
}
public static void Main(string[] args)
{
ConverterClass converter = new ConverterClass();
converter.ConvertVideo("my_video.avi");
/* you should watch for when the finished method
returns true, and then act accordingly */
/* as we are in a console, the host application (we)
may finish before the guest application (convert.exe),
so we need to wait here */
while(!converter.finished()) {
/* wait */
Thread.Sleep(100);
}
/* video finished converting */
doActionsAfterConversion();
}
}
當程序退出時,finishedFlag將被設置爲true,並完成()方法將開始返回這一點。看到主要的「你應該怎麼做」。
未找到函數退出「myProcess.Exited + = new EventHandler(myProcess_Exited);」 – 2010-12-02 08:49:58