I'm making a backup system and dealing with the fact System.FileWatcher is raising multiple events per change (copying a file raises Created and Changed, for one) by queueing the commands.
Right now, I'm subscribing to events:
watcher.Changed += new FileSystemEventHandler(OnChanged);
and creating an object of a class:
private void OnChanged(object sender, FileSystemEventArgs e)
{
var now = DateTime.Now;
var change = new ChangeCommand(now, _fileLogPath, e.FullPath);
}
ChangeCommand is a class that implements the ICommand interface. My question is how and when to actually enqueue them. Since trying to access a file that is being accessed would throw an exception, I want to keep Peek-ing until it doesn't and then Dequeue.
Aucun commentaire:
Enregistrer un commentaire