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
private static string _statusFile;
private static string _submitPath;
private static DateTime _statusAge;
private static ServiceConfig _config;
private static ServiceStatus _status;
private static bool _statusFileChanged = false;
private static bool _statusChanged = false;
private static bool _svcRunning = false;
private static bool _svcSuspended = true;
......@@ -120,6 +120,14 @@ namespace ATxTray
AppTimer.Enabled = true;
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.");
}
......@@ -219,6 +227,10 @@ namespace ATxTray
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) {
AutoTxTrayExit();
}
......@@ -343,13 +355,12 @@ namespace ATxTray
/// Read (or re-read) the service status file if it has changed since last time.
/// </summary>
private static void ReadStatus() {
var age = new FileInfo(_statusFile).LastWriteTime;
if (age == _statusAge)
if (!_statusFileChanged)
return;
Log.Trace("Status file was updated, trying to re-read...");
_statusAge = age;
Log.Debug("Status file was updated, trying to re-read...");
_status = ServiceStatus.Deserialize(_statusFile, _config);
_statusFileChanged = false;
}
/// <summary>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment