简体   繁体   English

无法使用System.Diagnostics创建新的程序实例

[英]Can't create new program instance using System.Diagnostics

My program's executable file's name is "foo.exe", and I'm trying to open another window of that same program. 我程序的可执行文件名为“ foo.exe”,我正试图打开该程序的另一个窗口。 I cannot open another window by creating a new Form1 and Showing that because of a custom control I'm using. 无法通过创建新的Form1并显示该窗口来打开另一个窗口,因为我正在使用自定义控件。 The only way to get to open a new window of my form properly is by starting the executable file again, "foo.exe". 正确打开我的窗体的新窗口的唯一方法是再次启动可执行文件“ foo.exe”。 So far, I've tried: 到目前为止,我已经尝试过:

System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
System.Diagnostics.Process.Start("foo.exe");
System.Diagnostics.Process.Start("\\foo.exe");

None of those work, unfortunately. 不幸的是,这些都不起作用。 So I tried this with both .Location and "foo.exe": 因此,我尝试同时使用.Location和“ foo.exe”:

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

After I observed the code using Task Manager, I've found that the process foo.exe is started and right away suspended. 在使用任务管理器观察代码后,我发现进程foo.exe已启动并立即挂起。

The same thing happens when I open from Command Prompt! 当我从命令提示符打开时,也会发生同样的事情! What should I do? 我该怎么办?

您可以尝试以下方法:

System.Diagnostics.Process.Start(Application.StartupPath + @"\YourApplicationName.exe");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM