启动另一个应用程序,但不启动新进程
本文关键字:启动 进程 新进程 另一个 应用程序 | 更新日期: 2023-09-27 18:32:54
所以我找到了
System.Diagnostics.Process.Start()
但是,然后我想关闭启动它的应用程序(我需要启动器连接到服务器、启动游戏并关闭自己),所以它不起作用。我的应用:
public partial class MainWindow : Window
{
Process.Start("xnagame.exe", "12345678");
this.Close();
}
命名进程,以便有一个句柄来关闭它。 并非所有进程都能正常关闭。
try
{
Process myProcess;
myProcess = Process.Start("Notepad.exe");
// Display physical memory usage 5 times at intervals of 2 seconds.
for (int i = 0;i < 5; i++)
{
if (!myProcess.HasExited)
{
// Discard cached information about the process.
myProcess.Refresh();
// Print working set to console.
Console.WriteLine("Physical Memory Usage: "
+ myProcess.WorkingSet.ToString());
// Wait 2 seconds.
Thread.Sleep(2000);
}
else {
break;
}
}
// Close process by sending a close message to its main window.
myProcess.CloseMainWindow();
// Free resources associated with process.
myProcess.Close();
}
catch(Exception e)
{
Console.WriteLine("The following exception was raised: ");
Console.WriteLine(e.Message);
}
使用 Process.Start(ProcessStartInfo)
重载,并将 UseShellExecute
属性设置为 true
。