Notification when WPF UI closes

后端 未结 2 1752
囚心锁ツ
囚心锁ツ 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:16

    You should try out the Closing event. This article provides useful information about when a WPF is actually closing (not just the window).

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题