mirror of
https://github.com/nomi-san/parsec-vdd.git
synced 2026-08-07 13:50:45 +00:00
app: move pinging loop to daemon thread
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace ParsecVDisplay
|
||||
{
|
||||
internal static class Daemon
|
||||
{
|
||||
static Thread EventThread;
|
||||
static CancellationTokenSource Cancellation;
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
Cancellation = new CancellationTokenSource();
|
||||
var token = Cancellation.Token;
|
||||
|
||||
EventThread = new Thread(() => EventLoop(token));
|
||||
EventThread.IsBackground = false;
|
||||
EventThread.Priority = ThreadPriority.Highest;
|
||||
|
||||
EventThread.Start();
|
||||
}
|
||||
|
||||
public static void Stop()
|
||||
{
|
||||
Cancellation?.Cancel();
|
||||
EventThread?.Join();
|
||||
}
|
||||
|
||||
static void EventLoop(CancellationToken cancellation)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (cancellation.IsCancellationRequested)
|
||||
break;
|
||||
|
||||
ParsecVDD.Ping();
|
||||
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,7 @@
|
||||
<DependentUpon>DisplayItem.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Config.cs" />
|
||||
<Compile Include="Daemon.cs" />
|
||||
<Compile Include="Device.cs" />
|
||||
<Compile Include="Display.cs" />
|
||||
<Compile Include="Helper.cs" />
|
||||
|
||||
@@ -45,7 +45,11 @@ namespace ParsecVDisplay
|
||||
if (InitDriver())
|
||||
{
|
||||
Helper.StayAwake(false);
|
||||
Daemon.Start();
|
||||
|
||||
Application.Run(new Tray());
|
||||
|
||||
Daemon.Stop();
|
||||
ParsecVDD.Uninit();
|
||||
}
|
||||
}
|
||||
|
||||
-10
@@ -16,7 +16,6 @@ namespace ParsecVDisplay
|
||||
static System.Windows.Controls.ContextMenu Menu;
|
||||
|
||||
Thread AppThread;
|
||||
System.Windows.Forms.Timer VddTimer;
|
||||
|
||||
ToolStripMenuItem MI_RunOnStartup;
|
||||
ToolStripMenuItem MI_RestoreDisplays;
|
||||
@@ -46,11 +45,6 @@ namespace ParsecVDisplay
|
||||
AppThread.SetApartmentState(ApartmentState.STA);
|
||||
AppThread.Start();
|
||||
|
||||
VddTimer = new System.Windows.Forms.Timer();
|
||||
VddTimer.Interval = 50;
|
||||
VddTimer.Tick += VddTimer_Tick;
|
||||
VddTimer.Start();
|
||||
|
||||
var appName = Program.AppName;
|
||||
var appIcon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
|
||||
|
||||
@@ -281,9 +275,6 @@ namespace ParsecVDisplay
|
||||
Config.DisplayCount = displays.Count;
|
||||
}
|
||||
|
||||
VddTimer.Tick -= VddTimer_Tick;
|
||||
VddTimer.Stop();
|
||||
|
||||
App.Current?.Dispatcher.Invoke(App.Current.Shutdown);
|
||||
AppThread.Join();
|
||||
|
||||
@@ -295,7 +286,6 @@ namespace ParsecVDisplay
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
VddTimer.Dispose();
|
||||
TrayIcon.Dispose();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user