如何从应用程序内部启动新的应用程序实例?

时间:2021-10-22 22:48:40

When the user clicks a button i want to start a new instance of my application.

当用户单击按钮时,我希望启动应用程序的新实例。

When i use this code it throws an error:

当我使用这段代码时,它会抛出一个错误:

new Application().Run();

Cannot create more than one System.Windows.Application instance in the same AppDomain.

不能创建多个System.Windows。在同一个AppDomain中的应用程序实例。

3 个解决方案

#1


6  

I have found the solution

我找到了解决方法。

Process p = new Process();
p.StartInfo.FileName = 
    System.Reflection.Assembly.GetExecutingAssembly().Location;
p.Start();

#2


2  

With another process:

与另一个过程:

#3


2  

Process p = new Process();
p.StartInfo.FileName = Application.ExecutablePath;
p.Start();

This is in winforms, but perhaps it's similar in WPF.

这是winforms (winforms),但在WPF中可能类似。

#1


6  

I have found the solution

我找到了解决方法。

Process p = new Process();
p.StartInfo.FileName = 
    System.Reflection.Assembly.GetExecutingAssembly().Location;
p.Start();

#2


2  

With another process:

与另一个过程:

#3


2  

Process p = new Process();
p.StartInfo.FileName = Application.ExecutablePath;
p.Start();

This is in winforms, but perhaps it's similar in WPF.

这是winforms (winforms),但在WPF中可能类似。