[問題] 關閉 BackgroundWorker 中的 process
我執行了一個BackgroundWorker去執行ExecuteAvid這個method
在這個method中 new process 去執行外部的exe檔
如果我想要在程式中 當exe檔執行還沒結束的時候
去中斷這個外部的exe檔的執行該怎麼做比較好
我找不到BackgroundWorker所在的thread
所以就算執行myprocess.close也是沒有用
嘗試用BackgroundWorker的disposed event去觸發
不過也是沒有辦法找到BackgroundWorker執行的thread
請問該怎樣才能關掉外部的exe檔
private BackgroundWorker back;
back = new BackgroundWorker();
back.DoWork += new DoWorkEventHandler(ExecuteAvid);
back.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CloseWindow);
back.RunWorkerAsync();
void ExecuteAvid(object sender, DoWorkEventArgs e)
{
Debug.WriteLine("back thread maybe");
Debug.WriteLine(String.Format("Thread ID = {0}", Thread.CurrentThread.ManagedThreadId));
myprocess = new Process();
try
{
myprocess.StartInfo.CreateNoWindow = true;
myprocess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
myprocess.StartInfo.Arguments = arg;
myprocess.StartInfo.FileName = folderPath + "//writeavidmxf.exe";
myprocess.Start();
myprocess.WaitForExit();
}
catch (Win32Exception e32)
{
Debug.WriteLine("win32Exception"+e32);
exe.Dispose();
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.211.242.19
→
02/17 18:21, , 1F
02/17 18:21, 1F
推
02/17 19:37, , 2F
02/17 19:37, 2F
推
02/17 19:42, , 3F
02/17 19:42, 3F
→
02/17 19:42, , 4F
02/17 19:42, 4F