public BackupEverySave(PersistentList <T> list, string listPath, string pathToSaveTheBackup, int maxNumberOfFilesToKeep = 10) { var backup = new FileSystemBackup(listPath, pathToSaveTheBackup, maxNumberOfFilesToKeep); list.Saved += (sender, args) => { Task.Run(() => { try { var backupPath = backup.Backup(); BackupAttempted?.Invoke(this, new BackupAttemptedEventArgs(backupPath)); } catch (BackupException ex) { BackupAttempted?.Invoke(this, new BackupAttemptedEventArgs(ex)); } }); }; }
private async Task Loop() { while (true) { await TimeMachine.Delay(TimeSpan.FromMinutes(1)); var currentHour = TimeMachine.Now.Hour; if (currentHour != _hourBase) { return; } try { var backupPath = _backup.Backup(); BackupAttempted?.Invoke(this, new BackupAttemptedEventArgs(backupPath)); } catch (BackupException ex) { BackupAttempted?.Invoke(this, new BackupAttemptedEventArgs(ex)); } } }