mirror of
https://github.com/chylex/Backup-Essentials.git
synced 2024-10-17 08:42:44 +02:00
30 lines
773 B
C#
30 lines
773 B
C#
using System;
|
|
using System.Windows.Threading;
|
|
|
|
namespace BackupEssentials.Utils{
|
|
class ScheduledUpdate{
|
|
public static ScheduledUpdate Forever(int seconds, Action update){
|
|
return new ScheduledUpdate(seconds,update);
|
|
}
|
|
|
|
public bool NeedsUpdate = false;
|
|
private readonly DispatcherTimer timer;
|
|
|
|
private ScheduledUpdate(int seconds, Action update){
|
|
timer = new DispatcherTimer();
|
|
timer.Interval = new TimeSpan(0,0,seconds);
|
|
|
|
timer.Tick += (sender, args) => {
|
|
if (NeedsUpdate){
|
|
NeedsUpdate = false;
|
|
update();
|
|
}
|
|
};
|
|
}
|
|
|
|
public void Start(){
|
|
timer.Start();
|
|
}
|
|
}
|
|
}
|