// initialize further instances, which are active (touched) private XmlStoreFilePersister(IBackgroundTaskRunner <XmlStoreFilePersister> runner, XmlStore store, ILogger logger, bool touched) { _runner = runner; _store = store; _logger = logger; if (_runner.TryAdd(this) == false) { _runner = null; // runner's down _released = true; // don't mess with timer return; } // runner could decide to run it anytime now if (touched == false) { return; } _logger.Debug <XmlStoreFilePersister>("Created, save in {WaitMilliseconds}ms.", WaitMilliseconds); _initialTouch = DateTime.Now; _timer = new Timer(_ => TimerRelease()); _timer.Change(WaitMilliseconds, 0); }
private void Repeat() { // again? if (_runner.IsCompleted) { return; // fail fast } if (_periodMilliseconds == 0) { return; // safe } Reset(); // re-latch // try to add again (may fail if runner has completed) // if added, re-start the timer, else kill it if (_runner.TryAdd(this)) { _timer.Change(_periodMilliseconds, 0); } else { Dispose(true); } }