监控文件或目录的变化的代码
下面的代码段是关于监控文件或目录的变化的代码,应该能对码农有用。
public void StartMonitor(string path)
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = path;
watcher.NotifyFilter = NotifyFilters.FileName;
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.EnableRaisingEvents = true;
}
private void OnChanged(object source, FileSystemEventArgs e)
{
string word = DocumentUtility.ConvertPdfToDoc(e.FullPath);
}