Skip to content
Snippets Groups Projects
Commit d28909bd authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Use FileSystemWatcher to monitor changes to the status file.

Refers to #23
parent 405ce889
No related branches found
No related tags found
No related merge requests found
...@@ -28,10 +28,10 @@ namespace ATxTray ...@@ -28,10 +28,10 @@ namespace ATxTray
private static string _statusFile; private static string _statusFile;
private static string _submitPath; private static string _submitPath;
private static DateTime _statusAge;
private static ServiceConfig _config; private static ServiceConfig _config;
private static ServiceStatus _status; private static ServiceStatus _status;
private static bool _statusFileChanged = false;
private static bool _statusChanged = false; private static bool _statusChanged = false;
private static bool _svcRunning = false; private static bool _svcRunning = false;
private static bool _svcSuspended = true; private static bool _svcSuspended = true;
...@@ -120,6 +120,14 @@ namespace ATxTray ...@@ -120,6 +120,14 @@ namespace ATxTray
AppTimer.Enabled = true; AppTimer.Enabled = true;
Log.Trace("Enabled timer."); Log.Trace("Enabled timer.");
var fsw = new FileSystemWatcher {
Path = baseDir,
NotifyFilter = NotifyFilters.LastWrite,
Filter = "status.xml",
};
fsw.Changed += StatusUpdated;
fsw.EnableRaisingEvents = true;
Log.Info("AutoTxTray initialization completed."); Log.Info("AutoTxTray initialization completed.");
} }
...@@ -219,6 +227,10 @@ namespace ATxTray ...@@ -219,6 +227,10 @@ namespace ATxTray
UpdateHoverText($"AutoTx [svc={serviceRunning}] [hb={heartBeat}] [tx={txProgress}]"); UpdateHoverText($"AutoTx [svc={serviceRunning}] [hb={heartBeat}] [tx={txProgress}]");
} }
private static void StatusUpdated(object sender, FileSystemEventArgs e) {
_statusFileChanged = true;
}
private void MiExitClick(object sender, EventArgs e) { private void MiExitClick(object sender, EventArgs e) {
AutoTxTrayExit(); AutoTxTrayExit();
} }
...@@ -343,13 +355,12 @@ namespace ATxTray ...@@ -343,13 +355,12 @@ namespace ATxTray
/// Read (or re-read) the service status file if it has changed since last time. /// Read (or re-read) the service status file if it has changed since last time.
/// </summary> /// </summary>
private static void ReadStatus() { private static void ReadStatus() {
var age = new FileInfo(_statusFile).LastWriteTime; if (!_statusFileChanged)
if (age == _statusAge)
return; return;
Log.Trace("Status file was updated, trying to re-read..."); Log.Debug("Status file was updated, trying to re-read...");
_statusAge = age;
_status = ServiceStatus.Deserialize(_statusFile, _config); _status = ServiceStatus.Deserialize(_statusFile, _config);
_statusFileChanged = false;
} }
/// <summary> /// <summary>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment