views:

20

answers:

2

while the application is running i'm using FileSystemWatcher to monitor the folder. But what if there are changes to the folder when the application is not running, how can I check for these changes when the application starts.

(similar to how windows media player, for example, monitors your music folder. Even when you add songs to that folder when it is not running, it does discover them when it runs next time)

Thanks

+2  A: 

You could store a list of what has already been found in a file and then compare it with the current state at startup.
Otherwise you could create a service that starts at system startup and always watches the folder and when your app starts up it polls the service for any changes since it last polled.

ho1
great, many thanks. i'm thinking, also, if I do create a service I should use it for when the application is running and when not running (instead of having two functins). do I get all the information I need from the log the service creates?
mazrabul
The only complication would be if your app wants to be told of changes immediately, since if the app didn't have it's own watcher you'd have to set up the service to send events to the app (when the app is running). Not sure if I understand your question about information though?
ho1
A: 

You can use the LastWriteTime which is in the System.IO.Directory or in the System.IO.DirectoryInfo.

Iraklis