43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using Microsoft.Win32;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace ProManagerPartner.Utils
|
|
{
|
|
public static class PowerModeEventHandler
|
|
{
|
|
//public static event Microsoft.Win32.PowerModeChangedEventHandler PowerModeChanged;
|
|
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
|
|
|
public static void InitEventHandler()
|
|
{
|
|
SystemEvents.PowerModeChanged += OnPowerModeChanged;
|
|
}
|
|
|
|
public static void OnPowerModeChanged(object sender, PowerModeChangedEventArgs e)
|
|
{
|
|
//Handle the event here.
|
|
if (e.Mode == PowerModes.Suspend)
|
|
{
|
|
logger.Debug("System is being suspended. Preparing...");
|
|
|
|
}
|
|
else if (e.Mode == PowerModes.Resume)
|
|
{
|
|
logger.Debug("System is no longer suspended. Restarting partner...");
|
|
Application.Current.MainWindow.UpdateLayout();
|
|
}
|
|
}
|
|
|
|
public static void DisposeEventHandler()
|
|
{
|
|
|
|
SystemEvents.PowerModeChanged -= OnPowerModeChanged;
|
|
}
|
|
}
|
|
}
|