Change timer behavior

Using the Stop method is not enough apparently
This commit is contained in:
Travis Nickles 2018-08-24 15:17:13 -05:00
parent ac360c426d
commit f2de4bc87d

View File

@ -246,7 +246,7 @@ namespace DS4Windows
*/ */
//tabProfiles.Controls.Add(opt); //tabProfiles.Controls.Add(opt);
autoProfilesTimer.Elapsed += CheckAutoProfiles; //autoProfilesTimer.Elapsed += CheckAutoProfiles;
autoProfilesTimer.Interval = 1000; autoProfilesTimer.Interval = 1000;
autoProfilesTimer.AutoReset = false; autoProfilesTimer.AutoReset = false;
@ -268,11 +268,12 @@ namespace DS4Windows
Enable_Controls(3, false); Enable_Controls(3, false);
btnStartStop.Text = Properties.Resources.StartText; btnStartStop.Text = Properties.Resources.StartText;
hotkeysTimer.Elapsed += Hotkeys; //hotkeysTimer.Elapsed += Hotkeys;
hotkeysTimer.AutoReset = false; hotkeysTimer.AutoReset = false;
if (SwipeProfiles) if (SwipeProfiles)
{ {
hotkeysTimer.Start(); ChangeHotkeysStatus(true);
//hotkeysTimer.Start();
} }
startToolStripMenuItem.Text = btnStartStop.Text; startToolStripMenuItem.Text = btnStartStop.Text;
@ -434,6 +435,34 @@ namespace DS4Windows
lbLastMessage.ForeColor = SystemColors.GrayText; lbLastMessage.ForeColor = SystemColors.GrayText;
} }
private void ChangeAutoProfilesStatus(bool state)
{
if (state)
{
autoProfilesTimer.Elapsed += CheckAutoProfiles;
autoProfilesTimer.Start();
}
else
{
autoProfilesTimer.Stop();
autoProfilesTimer.Elapsed -= CheckAutoProfiles;
}
}
private void ChangeHotkeysStatus(bool state)
{
if (state)
{
hotkeysTimer.Elapsed += Hotkeys;
hotkeysTimer.Start();
}
else
{
hotkeysTimer.Stop();
hotkeysTimer.Elapsed -= Hotkeys;
}
}
private void blankControllerTab() private void blankControllerTab()
{ {
for (int Index = 0, PadsLen = Pads.Length; for (int Index = 0, PadsLen = Pads.Length;
@ -602,8 +631,10 @@ namespace DS4Windows
turnOffTemp = true; turnOffTemp = true;
if (btnStartStop.Text == Properties.Resources.StopText) if (btnStartStop.Text == Properties.Resources.StopText)
{ {
autoProfilesTimer.Stop(); //autoProfilesTimer.Stop();
hotkeysTimer.Stop(); //hotkeysTimer.Stop();
ChangeAutoProfilesStatus(false);
ChangeHotkeysStatus(false);
this.Invoke((System.Action)(() => { this.Invoke((System.Action)(() => {
this.changingService = true; this.changingService = true;
@ -617,8 +648,10 @@ namespace DS4Windows
this.Invoke((System.Action)(() => this.Invoke((System.Action)(() =>
{ {
hotkeysTimer.Start(); //hotkeysTimer.Start();
autoProfilesTimer.Start(); ChangeHotkeysStatus(true);
ChangeAutoProfilesStatus(true);
//autoProfilesTimer.Start();
})); }));
} }
} }
@ -691,11 +724,13 @@ namespace DS4Windows
bool timerEnabled = autoProfilesTimer.Enabled; bool timerEnabled = autoProfilesTimer.Enabled;
if (pathCount > 0 && !timerEnabled) if (pathCount > 0 && !timerEnabled)
{ {
autoProfilesTimer.Start(); ChangeAutoProfilesStatus(true);
//autoProfilesTimer.Start();
} }
else if (pathCount == 0 && timerEnabled) else if (pathCount == 0 && timerEnabled)
{ {
autoProfilesTimer.Stop(); //autoProfilesTimer.Stop();
ChangeAutoProfilesStatus(false);
} }
} }
@ -942,12 +977,14 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
{ {
if (SwipeProfiles && !hotkeysTimer.Enabled) if (SwipeProfiles && !hotkeysTimer.Enabled)
{ {
hotkeysTimer.Start(); ChangeHotkeysStatus(true);
//hotkeysTimer.Start();
} }
if (programpaths.Count > 0 && !autoProfilesTimer.Enabled) if (programpaths.Count > 0 && !autoProfilesTimer.Enabled)
{ {
autoProfilesTimer.Start(); ChangeAutoProfilesStatus(true);
//autoProfilesTimer.Start();
} }
startToolStripMenuItem.Text = btnStartStop.Text = Properties.Resources.StopText; startToolStripMenuItem.Text = btnStartStop.Text = Properties.Resources.StopText;
@ -966,8 +1003,10 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
private void ServiceShutdownFinish() private void ServiceShutdownFinish()
{ {
hotkeysTimer.Stop(); ChangeAutoProfilesStatus(false);
autoProfilesTimer.Stop(); ChangeHotkeysStatus(false);
//hotkeysTimer.Stop();
//autoProfilesTimer.Stop();
startToolStripMenuItem.Text = btnStartStop.Text = Properties.Resources.StartText; startToolStripMenuItem.Text = btnStartStop.Text = Properties.Resources.StartText;
blankControllerTab(); blankControllerTab();
populateFullNotifyText(); populateFullNotifyText();
@ -2154,11 +2193,13 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
bool timerEnabled = hotkeysTimer.Enabled; bool timerEnabled = hotkeysTimer.Enabled;
if (swipe && !timerEnabled) if (swipe && !timerEnabled)
{ {
hotkeysTimer.Start(); ChangeHotkeysStatus(true);
//hotkeysTimer.Start();
} }
else if (!swipe && timerEnabled) else if (!swipe && timerEnabled)
{ {
hotkeysTimer.Stop(); ChangeHotkeysStatus(false);
//hotkeysTimer.Stop();
} }
} }