Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在显示应用程序主窗口之前运行可执行文件?_C#_Wpf_Multithreading_Process - Fatal编程技术网

C# 如何在显示应用程序主窗口之前运行可执行文件?

C# 如何在显示应用程序主窗口之前运行可执行文件?,c#,wpf,multithreading,process,C#,Wpf,Multithreading,Process,在我的WPF应用程序中,我希望在显示WPF窗口之前在App.cs中运行一个可执行文件,并在启动WPF应用程序之前等待进程退出 做这件事最好的方法是什么 我做到了,一切正常,但当我关闭我的wpf应用程序时,在退出时它会抛出14:03:11.8556778 System.InvalidOperationException中的dis-assembly异常:“Namespace.App”无法运行多次。在System.Windows.Application.RunInternal(窗口窗口窗口)在Syst

在我的WPF应用程序中,我希望在显示WPF窗口之前在
App.cs
中运行一个可执行文件,并在启动WPF应用程序之前等待进程退出


做这件事最好的方法是什么

我做到了,一切正常,但当我关闭我的wpf应用程序时,在退出时它会抛出14:03:11.8556778 System.InvalidOperationException中的dis-assembly异常:“Namespace.App”无法运行多次。在System.Windows.Application.RunInternal(窗口窗口窗口)在System.Windows.Application.Run(窗口窗口窗口)在System.Windows.Application.Run()添加p.Dispose();然后再次运行。相同,“应用程序不能运行多次。”进程p=Process.Start(info.FullName);p、 WaitForExit();p、 处置();运行(新的主窗口());谢谢你的帮助;如果我将添加Run(),则不会使wpf窗口显示,它将告诉我相同的异常。还有其他想法吗:p?您不应该在wpf应用程序中使用Run()。OnStartup在启动窗口(mainwindow)显示之前引发,因此无需调用Run()即可完全使用此代码
public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        Process p = Process.Start(@"exe file path");
        p.WaitForExit();
        p.Dispose();
        base.OnStartup(e);
    }
}