在OnPowerModeChanged事件之后,c#程序退出

时间:2016-10-02 21:12:21

标签: c# hibernate

我试图在休眠后重新启动一个程序很好,但是每次调用OnPowerModeChanged事件后,应用程序就会退出。知道发生了什么事吗?

static class Program
{
    [STAThread]
    static void Main()
    {
        SystemEvents.PowerModeChanged += OnPowerModeChanged;
        Application.Run();
    }

    private static void OnPowerModeChanged(object sender, PowerModeChangedEventArgs e)
    {
        if (e.Mode == PowerModes.Resume)
        {
            foreach (var process in Process.GetProcessesByName("someprogram"))
            {
                process.Kill(); //works
            }
            Process.Start(@"C:\someprogram.exe"); //works
        }
        //application just exits here???
    }
}

0 个答案:

没有答案