我写了一个小应用程序来监控文件的变化。当我运行它时,每次我得到关于路径的异常。我不明白为什么。路径是真实存在的。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Run();
}
public static void Run()
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"D:\test\1.txt";
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Changed +=new FileSystemEventHandler(watcher_Changed);
watcher.EnableRaisingEvents = true;
}
static void watcher_Changed(object sender, FileSystemEventArgs e)
{
Console.WriteLine(e.ChangeType);
}
}
}