如果在我的程序之外修改文件,如何得到通知? [英] How to get notified if a file was modified outside of my program?
问题描述
问题是,用户可能希望在任何时候使用外部程序编辑文件。如果发生这种情况,我希望我的程序能够得到通知,以便除了其他许多可能的操作之外,还更新该文件在其内存中相应的哈希码。 / p>
理想情况下,我想要通知一个新的线程或专用的后台线程,并执行必要的操作而不是主要的GUI线程。我正在使用ConcurrentDictionary和类似的线程安全的数据结构。
我正在使用C#5,Windows 7.
您正在寻找 FileSystemWatcher
$ b
侦听文件系统更改通知并在
a目录或文件目录中引发事件时,更改。
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.
You are looking for FileSystemWatcher
Listens to the file system change notifications and raises events when a directory, or file in a directory, changes.
这篇关于如果在我的程序之外修改文件,如何得到通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!