Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
auto-tx
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vamp
auto-tx
Commits
d28909bd
Commit
d28909bd
authored
7 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Use FileSystemWatcher to monitor changes to the status file.
Refers to
#23
parent
405ce889
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ATxTray/AutoTxTray.cs
+16
-5
16 additions, 5 deletions
ATxTray/AutoTxTray.cs
with
16 additions
and
5 deletions
ATxTray/AutoTxTray.cs
+
16
−
5
View file @
d28909bd
...
...
@@ -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>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment