你没装vs,还是没在+=后面直接tab帮你生成方法块……
手写事件订阅表达式时,可利用 VS 提供的功能,而不需记忆长长的类型名 键入 fsw.Created += 后按一次 Tab 键就会产生 new FileSystemEventHandler(方法名),再按一次 Tab 键,就生成了处理方法框架
Created是创建就立刻触发的,所以你如果再事件中立刻就去读取文件的话,可能出现文件被占用,所以你应该延迟一段时间后再去读取,保证不会异常
[quote=引用 2 楼 alexshyong 的回复:] 这个帖子说得很详细:http://blog.csdn.net/hwt0101/article/details/8469285 FileSystemWatcher fsw= new FileSystemWatcher(); fsw.Path = “D:\\Parg”; //设置监控的文件目录 fsw.IncludeSubdirectories = true; //设置监控C盘目录下的所有子目录 fsw.Filter = "*.txt"; //设置监控文件的类型 fsw.NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.Size; fsw.Created += new FileSystemEventHandler(this.fileSystemWatcher_EventHandle); //绑定事件触发后处理数据的方法。 fsw.EnableRaisingEvents = true; //启动监控 如果需要同时监控多个文件(如监控系统全盘),只需要创建FileSystemWatcher数组,每个文件用一个FileSystemWatcher进行监控。
直接工具箱拖一个FileSystemWatcher就可以了
这个帖子说得很详细:http://blog.csdn.net/hwt0101/article/details/8469285 FileSystemWatcher fsw= new FileSystemWatcher(); fsw.Path = “D:\\Parg”; //设置监控的文件目录 fsw.IncludeSubdirectories = true; //设置监控C盘目录下的所有子目录 fsw.Filter = "*.txt"; //设置监控文件的类型 fsw.NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.Size; fsw.Created += new FileSystemEventHandler(this.fileSystemWatcher_EventHandle); //绑定事件触发后处理数据的方法。 fsw.EnableRaisingEvents = true; //启动监控 如果需要同时监控多个文件(如监控系统全盘),只需要创建FileSystemWatcher数组,每个文件用一个FileSystemWatcher进行监控。
[quote=引用 3 楼 kfmao2004 的回复:] [quote=引用 2 楼 alexshyong 的回复:] 这个帖子说得很详细:http://blog.csdn.net/hwt0101/article/details/8469285 FileSystemWatcher fsw= new FileSystemWatcher(); fsw.Path = “D:\\Parg”; //设置监控的文件目录 fsw.IncludeSubdirectories = true; //设置监控C盘目录下的所有子目录 fsw.Filter = "*.txt"; //设置监控文件的类型 fsw.NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.Size; fsw.Created += new FileSystemEventHandler(this.fileSystemWatcher_EventHandle); //绑定事件触发后处理数据的方法。 fsw.EnableRaisingEvents = true; //启动监控 如果需要同时监控多个文件(如监控系统全盘),只需要创建FileSystemWatcher数组,每个文件用一个FileSystemWatcher进行监控。
111,092
社区成员
642,554
社区内容
加载中
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧