标签:属性 注册 nts ble 对象 变化 register send c#
要检查的变化,即从目录中删除目录或文件或文件夹、或者添加到一个新的文件或文件夹到一个目录下,我们必须使用FileSystemWatcher类。这个类允许我们通过程序来监控目录的变化。
创建一个新的FileSystemWatcher对象,Path属性指定的目录,并注册创建和删除事件。
并打开EnableRaisingEvents属性设置为true。
FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = @"c:\mydir"; // Register for events watcher.Created += new FileSystemEventHandler(watcher_Changed); watcher.Deleted += new FileSystemEventHandler(watcher_Changed); // Start Watching watcher.EnableRaisingEvents = true; // Event Handler static void watcher_Changed(object sender,FileSystemEventArgs e) { Console.WriteLine("Directory changed({0}): 小贝", e.ChangeType, e.FullPath); }
标签:属性 注册 nts ble 对象 变化 register send c#
原文地址:http://www.cnblogs.com/testsec/p/6102638.html