Notification when WPF UI closes

后端 未结 2 1784
囚心锁ツ
囚心锁ツ 2021-01-24 09:28

I am opening a WPF window from a tray app. I use the following code to open the window:

        if (gui == null)
        {
            gui = new App();
                  


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-24 10:33

    Josh was able to give the correct solution. You can see his answer here.

    Basically, I needed to start the WPF as a separate process, and then use the MyProcess.WaitForEnd() call. I added this to a thread so it wouldn't block the Tray. The code is as follows:

    Process myProcess = new Process();
    myProcess.StartInfo.UseShellExecute = false;
    myProcess.StartInfo.FileName = "C:\\mysettingsapp\\mysettingsapp.exe"; // replace with path to your settings app
    myProcess.StartInfo.CreateNoWindow = false;
    myProcess.Start();
    // the process is started, now wait for it to finish
    myProcess.WaitForExit();  // use WaitForExit(int) to establish a timeout
    

提交回复
热议问题