Application.Current.Shutdown() is not killing my application

后端 未结 7 905
执念已碎
执念已碎 2021-02-05 03:39

I\'ve just started a new C#/WPF application and am using the NotifyIcon from the WPF Contrib project. I can start the program, add an \"Exit\" MenuItem to the NotifyIcon\'s Cont

7条回答
  •  萌比男神i
    2021-02-05 04:12

    I have had the same problem in my application. In my start up module (Startup.cs) I found that this works for me:

    Process.GetCurrentProcess().Kill();
    

    The code is as follows:

    class StartUp
    {
        [STAThread]
        public static void Main()
        {
    
        try
        {
            Process[] processes = new Process[6];
            App app = new App();
            app.InitializeComponent();
            app.Run();
            Process.GetCurrentProcess().Kill(); //Must add this line after app.Run!!!
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message);
        }
        }
    

    This goes directly to the process causing the hang. There is no need to iterate through multiple processes.

提交回复
热议问题