简体   繁体   中英

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. I cannot open another window by creating a new Form1 and Showing that because of a custom control I'm using. The only way to get to open a new window of my form properly is by starting the executable file again, "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":

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.

The same thing happens when I open from Command Prompt! What should I do?

您可以尝试以下方法:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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