I'm creating a File Watcher BackgroundService
where once a file has been moved to my target folder, I need to give it X minutes before I then processed with my application.
I have the file watcher set up on my target folder like so:
public void WatchTargetFolder(string folderLocation, string fileName = "")
{
if (fileName == "") fileName = "Test";
_watcher.Path = folderLocation;
_watcher.NotifyFilter = NotifyFilters.LastWrite;
_watcher.Filter = $"{fileName}.xlsx";
_watcher.Changed += OnChanged;
_watcher.EnableRaisingEvents = true;
}
private void OnChanged(object source, FileSystemEventArgs e)
{
}
What is the best way to track the time since my file was last written to (as I've got in my NotifyFilter
)? So that once the time has passed, my file will then move.