1

A portion of my program has to keep track of a group of files, including their paths and hash codes in the memory.

Problem is, a user might like to edit the file using an external program at any point in time.

If this happens, I want my program to get notified so it updates the corresponding hash code of that file in its memory in addition to a number of other possible actions.

Ideally, I would like a new thread or a dedicated background thread to be notified and do the necessary action instead of the main GUI thread. I am using ConcurrentDictionary and similar thread-safe data structures.

I am using C# 5, Windows 7.

xander
  • 1,427
  • 2
  • 16
  • 26

3 Answers3

3

You are looking for FileSystemWatcher

Listens to the file system change notifications and raises events when a directory, or file in a directory, changes.

Habib
  • 219,104
  • 29
  • 407
  • 436
  • 1
    yes ! It seems that it even raises the events in separate threads (http://stackoverflow.com/a/11492747/792731) ! Thank you so much, I couldn't believe it was that straighforward ! – xander May 24 '13 at 06:02
2

Have you checked the FileSystemWatcher class?

Perhaps this class can help you to get notifies when files are changing.

Jonas W
  • 3,200
  • 1
  • 31
  • 44
2

The FileSystemWatcher component can do that for you:
http://msdn.microsoft.com/en-us/library/342da5th(v=vs.71).aspx

I've tried it before in a similar fashion like you describe, works perfectly.

Alexander
  • 2,457
  • 1
  • 14
  • 17