希望C#程序启动WPF应用程序

时间:2022-11-07 01:25:23

I've found a need to launch a WPF application from inside a c# program. I had written a simple WPF browser called eBrowse as an exercise for me. Then, I was requested to add it to a c# program that is already in use.

我发现需要从c#程序中启动WPF应用程序。我编写了一个名为eBrowse的简单WPF浏览器作为练习。然后,我被要求将它添加到已经使用的c#程序中。

I tried System.Diagnostics.Process.Start(@"C:\eBrowse"); but it didn't work.

我试过System.Diagnostics.Process.Start(@“C:\ eBrowse”);但它不起作用。

Another possibility that was found on a website:

在网站上发现的另一种可能性:

myProcess.StartInfo.UseShellExecute = true;
// You can start any process, HelloWorld is a do-nothing example.
//myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
myProcess.StartInfo.FileName = @"C:\eBrowse";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
// This code assumes the process you are starting will terminate itself. 
// Given that is is started without a window so you cannot terminate it 
// on the desktop, it must terminate itself or you can do it programmatically
// from this application using the Kill method.

I am wondering if it may not be possible to launch a WPF app from c#. Any ideas would be great.

我想知道是否可能无法从c#启动WPF应用程序。任何想法都会很棒。

4 个解决方案

#1


1  

using System.Diagnostics;

Process myProc;
myProc = Process.Start("calc.exe");

Compiled and run on my system with visual studio 2008/10.

使用visual studio 2008/10在我的系统上编译并运行。

Just swap calc.exe with the full path to your exe.

只需将calc.exe与exe的完整路径交换即可。

#2


5  

I think you are not specifying your EXE name. Try following:

我想你没有指定你的EXE名称。试试以下:

myProcess.StartInfo.FileName = @"C:\eBrowse\yourEXeName.exe"; 

#3


1  

remember to add the .exe extension. CreateNoWindow should be false.

记得添加.exe扩展名。 CreateNoWindow应该是false。

#4


0  

Will this work for you? Winforms/WPF interoperability

这对你有用吗? Winforms / WPF互操作性

#1


1  

using System.Diagnostics;

Process myProc;
myProc = Process.Start("calc.exe");

Compiled and run on my system with visual studio 2008/10.

使用visual studio 2008/10在我的系统上编译并运行。

Just swap calc.exe with the full path to your exe.

只需将calc.exe与exe的完整路径交换即可。

#2


5  

I think you are not specifying your EXE name. Try following:

我想你没有指定你的EXE名称。试试以下:

myProcess.StartInfo.FileName = @"C:\eBrowse\yourEXeName.exe"; 

#3


1  

remember to add the .exe extension. CreateNoWindow should be false.

记得添加.exe扩展名。 CreateNoWindow应该是false。

#4


0  

Will this work for you? Winforms/WPF interoperability

这对你有用吗? Winforms / WPF互操作性