1

我需要在我的 WPF 项目下运行一个外部 exe“ embed.exe ”,

这是一个片段

ProcessStartInfo processInf = new ProcessStartInfo("embed.exe");
processInf.Arguments = string.Format(@"Some arguments");
processInf.WindowStyle = ProcessWindowStyle.Hidden;
Process run = Process.Start(processInf);

我的问题是它阻止了我的用户界面,

有没有办法使用线程或任何不会阻塞 UI 的代码来包含embed.exe ?

4

2 回答 2

1

好的,

尝试将之前的代码片段放入方法中,然后创建一个新线程并将其初始化为该方法。

这是制作方法 //hone 代码

private void EmbedMethod()
{
ProcessStartInfo processInf = new ProcessStartInfo("embed.exe");
processInf.Arguments = string.Format(@"Some arguments");
processInf.WindowStyle = ProcessWindowStyle.Hidden;
Process run = Process.Start(processInf);
}

Thread embedThread=new Thread(EmbedMethod);
embedThread.start();
于 2013-02-16T17:26:57.233 回答
0

您启动的进程在其自己的线程上运行,而不是您的应用程序用来启动它的线程。

要终止您的 embed.exe 进程,您需要保留对已启动进程的引用。在这种情况下,运行变量。要终止进程调用:run.CloseMainWindow() 或 run.Kill()。Kill 强制终止进程,而 CloseMainWindow 只请求终止。

于 2013-02-18T02:32:38.793 回答