-2

所以我发现

System.Diagnostics.Process.Start()

但是,然后我想关闭启动它的应用程序(我需要启动器连接到服务器,启动游戏并自行关闭)所以它不起作用。我的应用程序:

public partial class MainWindow : Window
{
    Process.Start("xnagame.exe", "12345678");
    this.Close();
}
4

2 回答 2

1

命名进程,以便您有一个句柄来关闭它。并非所有进程都能正常关闭。

     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);
     }
于 2012-05-01T19:28:31.373 回答
0

使用Process.Start(ProcessStartInfo)重载,并将UseShellExecute属性设置为true

于 2012-05-01T20:24:54.633 回答