日期:2014-05-16 浏览次数:20999 次
try
{
var fw = new FileSystemWatcher(@"d:\");
fw.Changed += (source, e) => Console.WriteLine("检测到变化");
Console.ReadKey();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
fw.EnableRaisingEvents = true;
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")]
static void Main(string[] args)
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.NotifyFilter = NotifyFilters.LastAccess
------解决方案--------------------
NotifyFilters.LastWrite
------解决方案--------------------
NotifyFilters.FileName
------解决方案--------------------
NotifyFilters.DirectoryName;
watcher.Filter = "*.*";
watcher.Path = "D:\\test";
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
watcher.EnableRaisingEvents = true;
Console.WriteLine("Press \'q\' to quit the sample.");
while (Console.Read() != 'q') ;
}
&n