private async Task AsyncAction() {
Debug.WriteLine("ACMGR: WatchingTask.AsyncAction()");
while (_delay) {
_delay = false;
Debug.WriteLine("ACMGR: WatchingTask.AsyncAction() Delay");
await Task.Delay(_queue.Any() && _queue.Peek().Type == WatcherChangeTypes.Deleted ? 300 : 200);
}
Application.Current.Dispatcher.Invoke(() => {
Debug.WriteLine("ACMGR: WatchingTask.AsyncAction() Invoke");
// in some cases (CREATED, DELETED) queue could be cleared
if (_queue.Any()) {
var change = _queue.Dequeue();
_applier.ApplyChange(_location, change);
if (_queue.Any()) {
if (change.Type == WatcherChangeTypes.Changed) {
// very special case:
// after CHANGED could be only CHANGED, and only with FULL_FILENAME
// let’s process all of them in one INVOKE
foreach (var next in _queue) {
_applier.ApplyChange(_location, next);
}
_queue.Clear();
} else {
Debug.WriteLine("ACMGR: WatchingTask.AsyncAction() Next");
AsyncAction().Forget();
return;
}
}
}
_delay = false;
_actionInProcess = false;
});
}