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:
与另一个过程:
- Get the program path (e.g. via
Environment.CommandLine
) - 获取程序路径(例如,通过Environment.CommandLine)
- Start a process with said path
- 使用该路径启动进程
#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:
与另一个过程:
- Get the program path (e.g. via
Environment.CommandLine
) - 获取程序路径(例如,通过Environment.CommandLine)
- Start a process with said path
- 使用该路径启动进程
#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中可能类似。