Skip to content

Commit

Permalink
Merge pull request #261 from Forgenn/fix-sleep
Browse files Browse the repository at this point in the history
Fix application not reconnecting after sleep
  • Loading branch information
XScorpion2 authored May 3, 2022
2 parents 69e5551 + b6fa832 commit 1fe5a2e
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define POLLING_SERIAL

using MaxMix.Framework;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -49,12 +50,30 @@ public class CommunicationService
public Action<string> OnFirmwareIncompatible;
public Action<Command, IMessage> OnMessageRecieved;

void OnPowerChange(Object sender, PowerModeChangedEventArgs e)
{
switch (e.Mode)
{
case PowerModes.Resume:
Start();
break;
case PowerModes.Suspend:
Stop();
break;
default:
break;
}
}

public void Start()
{
m_Stopping = false;
m_Thread = new Thread(Update);
m_Thread.Name = "Communication Service";
m_Thread.Start();

SystemEvents.PowerModeChanged -= OnPowerChange;
SystemEvents.PowerModeChanged += OnPowerChange;
}

public void Stop()
Expand Down

0 comments on commit 1fe5a2e

Please sign in to comment.