So far I have tried this code which shows for 1 file last update.
FileInfo fileInfo = new FileInfo(@"C:\Users\Desktop\test.xlsx"); DateTime lastWriteTime = fileInfo.LastWriteTime; Console.WriteLine(lastWriteTime); MessageBox.Show("test" + lastWriteTime);
I want to know how this could be automatically ran every 24 hrs as I need to perform a check on various files of more than 1 folder based on the file system.
How to make it a windows service which runs in background.
One potential solution here is to create a Windows service as mentioned. TopShelf is an open source project that can help you quickly create Windows services that are easy to install and uninstall. The documentation is a little sparse but it’s relatively easy to use the example to get up and running. Tangentially, I’d also like to give you some advice about the FileSystemWatcher that I’ve learned through experience: You’ll want to “watch” for a minute or two at a time, or some interval that’s reasonable, then recreate the watcher again. If the underlying file system falls out from under the FileSystemWatcher, it won’t know. This can make it seem like the FileSystemWatcher “doesn’t work”.