Skip to content
Permalink
Browse files

GSDumpGUI: Replaced watchdog thread with Forms.Timer

Explicit dispose of watchers and timer on Form dispose, also event enum.
  • Loading branch information...
KrossX authored and lightningterror committed Aug 3, 2019
1 parent 77f52cf commit c0a38b45f16b882ef782bab06ee7e9fd59dea7e6
Showing with 49 additions and 28 deletions.
  1. +5 −5 tools/GSDumpGUI/Core/Program.cs
  2. +5 −2 tools/GSDumpGUI/Forms/frmMain.Designer.cs
  3. +39 −21 tools/GSDumpGUI/Forms/frmMain.cs
@@ -48,7 +48,6 @@ static class Program

static private TreeNode CurrentNode;
static public IntPtr hMainIcon;
static public bool isProgRunning;

[STAThread]
static void Main(String[] args)
@@ -118,14 +117,15 @@ static void Main(String[] args)
Server.OnClientAfterConnect += new TCPLibrary.Core.Server.ConnectedHandler(Server_OnClientAfterConnect);
Server.OnClientAfterDisconnected += new TCPLibrary.Core.Server.DisconnectedHandler(Server_OnClientAfterDisconnected);
Server.Enabled = true;
isProgRunning = true;

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
frmMain = new GSDumpGUI();
Application.Run(frmMain);

isProgRunning = false;
using (frmMain = new GSDumpGUI())
{
Application.Run(frmMain);
}

Server.Enabled = false;
}
}

Some generated files are not rendered by default. Learn more.

@@ -22,13 +22,11 @@
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using System.Diagnostics;
using System.Linq;
@@ -97,7 +95,9 @@ public Int32 SelectedRad
private List<FileSystemWatcher> _dllWatcher;
private List<FileSystemWatcher> _dumpWatcher;

private ConcurrentQueue<int> _watcherEvents;
enum FileChangeEvt { Dll = 1, Dump = 2 };
private ConcurrentQueue<FileChangeEvt> _watcherEvents;
private System.Windows.Forms.Timer _fileChangesWatchdog;

private string _gsdxPathOld, _dumpPathOld;

@@ -136,41 +136,59 @@ public GSDumpGUI()

_dllWatcher = new List<FileSystemWatcher>();
_dumpWatcher = new List<FileSystemWatcher>();
_watcherEvents = new ConcurrentQueue<int>();
_watcherEvents = new ConcurrentQueue<FileChangeEvt>();

Thread watcherThread = new Thread(ChangesWatchdogThread);
watcherThread.Start();
_fileChangesWatchdog = new System.Windows.Forms.Timer();
_fileChangesWatchdog.Tick += new EventHandler(FileChangesWatchdog);
_fileChangesWatchdog.Interval = 1000;
_fileChangesWatchdog.Start();
}

private void ChangesWatchdogThread()
private void DisposeExtra()
{
while (Program.isProgRunning)
foreach (FileSystemWatcher w in _dllWatcher)
{
bool dllReload = false;
bool dumpReload = false;
w.EnableRaisingEvents = false;
w.Dispose();
}

int evt;
while (_watcherEvents.TryDequeue(out evt))
{
if (evt == 1) dllReload = true;
else if (evt == 2) dumpReload = true;
}
foreach (FileSystemWatcher w in _dumpWatcher)
{
w.EnableRaisingEvents = false;
w.Dispose();
}

if (dllReload) this.Invoke((MethodInvoker)delegate { ReloadGsdxDlls(); });
if (dumpReload) this.Invoke((MethodInvoker)delegate { ReloadGsdxDumps(); });
_dllWatcher.Clear();
_dumpWatcher.Clear();

_fileChangesWatchdog.Stop();
_fileChangesWatchdog.Dispose();
}

Thread.Sleep(1000);
private void FileChangesWatchdog(object source, EventArgs e)
{
bool dllReload = false;
bool dumpReload = false;

FileChangeEvt evt;
while (_watcherEvents.TryDequeue(out evt))
{
if (evt == FileChangeEvt.Dll) dllReload = true;
else if (evt == FileChangeEvt.Dump) dumpReload = true;
}

if (dllReload) ReloadGsdxDlls();
if (dumpReload) ReloadGsdxDumps();
}

private void OnDllDirChange(object source, FileSystemEventArgs e)
{
_watcherEvents.Enqueue(1);
_watcherEvents.Enqueue(FileChangeEvt.Dll);
}

private void OnDumpDirChange(object source, FileSystemEventArgs e)
{
_watcherEvents.Enqueue(2);
_watcherEvents.Enqueue(FileChangeEvt.Dump);
}

private static void BindListControl<TModel, TElement>(ListControl lb, TModel model, Func<TModel, BindingList<TElement>> collectionAccessor, Expression<Func<TElement, string>> displayTextAccessor, Expression<Func<TModel, int>> selectedIndexAccessor)

0 comments on commit c0a38b4

Please sign in to comment.
You can’t perform that action at this time.