我试图在休眠后重新启动一个程序很好,但是每次调用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???
}
}