diff --git a/BodyshopUploader/App.xaml.cs b/BodyshopUploader/App.xaml.cs
index 74ebe40..8e80f61 100644
--- a/BodyshopUploader/App.xaml.cs
+++ b/BodyshopUploader/App.xaml.cs
@@ -1,4 +1,5 @@
-using System;
+using Microsoft.Win32;
+using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
@@ -21,6 +22,7 @@ namespace BodyshopPartner
private void Application_Exit(object sender, ExitEventArgs e)
{
+ Utils.PowerModeEventHandler.DisposeEventHandler();
BodyshopPartner.Properties.Settings.Default.Save();
Utils.QuickBooksInterop.DisconnectFromQuickBooks();
}
diff --git a/BodyshopUploader/ImEXOnlinePartner.csproj b/BodyshopUploader/ImEXOnlinePartner.csproj
index 9fb04f6..ae0f207 100644
--- a/BodyshopUploader/ImEXOnlinePartner.csproj
+++ b/BodyshopUploader/ImEXOnlinePartner.csproj
@@ -400,6 +400,7 @@
+
diff --git a/BodyshopUploader/Utils/PowerModeEventHandler.cs b/BodyshopUploader/Utils/PowerModeEventHandler.cs
new file mode 100644
index 0000000..2d7bccc
--- /dev/null
+++ b/BodyshopUploader/Utils/PowerModeEventHandler.cs
@@ -0,0 +1,42 @@
+using Microsoft.Win32;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace BodyshopPartner.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;
+ }
+ }
+}
diff --git a/BodyshopUploader/ViewModels/MainViewModel.cs b/BodyshopUploader/ViewModels/MainViewModel.cs
index f992b18..48fe92e 100644
--- a/BodyshopUploader/ViewModels/MainViewModel.cs
+++ b/BodyshopUploader/ViewModels/MainViewModel.cs
@@ -82,6 +82,7 @@ namespace BodyshopPartner.ViewModels
Task.Run(() => Utils.HTTPServer.InitHttpServer(AddHttpStatus));
Task.Run(() => updateCheck());
StartAllFolderMonitors();
+ Utils.PowerModeEventHandler.InitEventHandler();
_callingThread.ReportProgress(100);
}