Files
BeWoPlaner/BeWo/Core/AutoLockUI.cs

84 lines
2.1 KiB
C#
Raw Permalink Normal View History

2016-06-27 01:45:38 +02:00
using System;
namespace BeWo.Core
{
public static class AutoLockUI
{
private static System.Windows.Forms.Timer _Timer;
public static int LockUITime { get; set; }
public delegate void DoAutoLockUI();
public static event DoAutoLockUI DoAutoLockUIEvent;
2018-02-19 10:52:48 +01:00
public static bool HasJustBeenUnlocked { get; set; }
public static void StartAutoLockUIOption()
2016-06-27 01:45:38 +02:00
{
2018-02-19 10:52:48 +01:00
HasJustBeenUnlocked = false;
2016-06-27 01:45:38 +02:00
System.Windows.Interop.ComponentDispatcher.ThreadIdle += DispatcherQueueEmptyHandler;
}
2018-02-19 10:52:48 +01:00
private static void _timerTick(object sender, EventArgs e)
2016-06-27 01:45:38 +02:00
{
2018-02-19 10:52:48 +01:00
if (_Timer == null)
{
return;
}
2016-06-27 01:45:38 +02:00
System.Windows.Interop.ComponentDispatcher.ThreadIdle -= DispatcherQueueEmptyHandler;
_Timer.Stop();
_Timer = null;
2018-02-19 10:52:48 +01:00
DoAutoLockUIEvent?.Invoke();
2016-06-27 01:45:38 +02:00
}
public static void StopTimer()
{
2018-02-19 10:52:48 +01:00
if (_Timer == null)
{
return;
}
2016-06-27 01:45:38 +02:00
System.Windows.Interop.ComponentDispatcher.ThreadIdle -= DispatcherQueueEmptyHandler;
_Timer.Stop();
_Timer = null;
}
2018-02-19 10:52:48 +01:00
private static void DispatcherQueueEmptyHandler(object sender, EventArgs e)
2016-06-27 01:45:38 +02:00
{
if (_Timer == null)
{
if (LockUITime > 0)
{
_Timer = new System.Windows.Forms.Timer {Interval = LockUITime*60*1000};
_Timer.Tick += _timerTick;
_Timer.Enabled = true;
}
}
else if (_Timer.Enabled == false)
{
_Timer.Enabled = true;
}
else
{
if (LockUITime == 0)
2018-02-19 10:52:48 +01:00
{
StopTimer();
}
2016-06-27 01:45:38 +02:00
}
}
public static void ResetLockUITimer()
{
2018-02-19 10:52:48 +01:00
if (_Timer == null)
{
return;
}
2016-06-27 01:45:38 +02:00
_Timer.Enabled = false;
_Timer.Enabled = true;
}
}
}