多线程监控文件夹,FlieSystemWatcher,并使用共享函数
发表于: 2011-01-06 09:55:47
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
using System;using System.Collections.Generic;using System.Text;using System.Threading;using System.IO;using System.Collections;namespace Thread_FileSystemWatcher{ class Program { private static Thread[] threads; private static string[] pPath; static void Main(string[] args) { threadsPEIZHI(); while (Console.Read() != 'q') ; } static void threadsPEIZHI() { try { pPath = new string[2]; pPath[0] = "c:\\"; pPath[1] = "e:\\"; threads = new Thread[pPath.Length]; for (int i = 0; i <= threads.Length-1; i++) { threads[i] = new Thread(Run); threads[i].Name = pPath[i]; threads[i].Start(); Console.WriteLine(threads[i].Name); } } catch(Exception Ex) { Console.WriteLine(Ex.Message); } } static void Run() { Run(Thread.CurrentThread.Name); } static void Run(string pPath) { FileSystemWatcher fsw = new FileSystemWatcher(pPath); fsw.Filter = "*.*";//监控所有类型,包括子文件夹 fsw.NotifyFilter = NotifyFilters.DirectoryName | NotifyFilters.LastAccess | NotifyFilters.LastWrite; fsw.Changed += new FileSystemEventHandler(OnChanged); fsw.Created += new FileSystemEventHandler(OnCreated); fsw.Deleted += new FileSystemEventHandler(OnDeleted); fsw.Renamed += new RenamedEventHandler(OnRenamed); fsw.EnableRaisingEvents = true;//开启监控 } static void OnChanged(object source,FileSystemEventArgs e) { Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType); } static void OnCreated(object source,FileSystemEventArgs e) { Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType); } static void OnDeleted(object source,FileSystemEventArgs e) { Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType); } static void OnRenamed(object source, RenamedEventArgs e) { Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath); } }} |
请指教!
多线程监控文件夹,FlieSystemWatcher,并使用共享函数的更多相关文章
- Python 的 pyinotify 模块 监控文件夹和文件的变动
官方参考: https://github.com/seb-m/pyinotify/wiki/Events-types https://github.com/seb-m/pyinotify/wiki/I ...
- Storm监控文件夹变化 统计文件单词数量
监控指定文件夹,读取文件(新文件动态读取)里的内容,统计单词的数量. FileSpout.java,监控文件夹,读取新文件内容 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
- 【.Net 学习系列】-- FileSystemWatcher 监控文件夹新生成文件,并在确认文件没有被其他程序占用后将其移动到指定文件夹
监控文件夹测试程序: using System; using System.Collections.Generic; using System.IO; using System.Linq; using ...
- [转帖]Linux下inotify监控文件夹状态,发生变化后触发rsync同步
Linux下inotify监控文件夹状态,发生变化后触发rsync同步 https://www.cnblogs.com/fjping0606/p/6114123.html 1.安装工具--inotif ...
- 152-技巧-Power Query 快速合并文件夹中表格之自定义函数 TableXlsxCsv
152-技巧-Power Query 快速合并文件夹中表格之自定义函数 TableXlsxCsv 附件下载地址:https://jiaopengzi.com/2602.html 一.背景 在我们使用 ...
- 使用TheFolderSpy监控文件夹的变化-邮件通知
一.概述 当我们的文档或者代码文件发布在公网.共享文件夹中,其他用户具备访问或修改的权限时,就存在文档被覆盖或删除的分享.另外一个典型的场景,发布在Web服务器上的网页文件,在网站版本不更新的时间,服 ...
- delphi监控文件夹
(****************************************** 文件和目录监控 当磁盘上有文件或目录操作时,产生事件 使用方法: 开始监控: PathWatch(Self.Ha ...
- Java多线程遍历文件夹,广度遍历加多线程加深度遍历结合
复习IO操作,突然想写一个小工具,统计一下电脑里面的Java代码量还有注释率,最开始随手写了一个递归算法,遍历文件夹,比较简单,而且代码层次清晰,相对易于理解,代码如下:(完整代码贴在最后面,前面是功 ...
- 使用FileSystemWatcher监控文件夹及文件
引言 这一周主要精力集中学习一个同事开发的本地文件搜索项目上,其中客户端添加共享文件时主要是使用FileSystemWatcher 监控文件,并在各种事件发生时向服务器发送消息. 解决方法 FileS ...
随机推荐
- wordpress数据库优化-关闭日志修订
每次在wordpress网站修改文章的时候都会产生一个修订版本,wp_posts会产生一个post_type为“REVISIONS”的记录,修改次数一多的话,那修订版本就有几万条记录了 在functi ...
- Javascript 电子时钟源码
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- 表单插件——form
表单插件——form 通过表单form插件,调用ajaxForm()方法,实现ajax方式向服务器提交表单数据,并通过方法中的options对象获取服务器返回数据,调用格式如下: $(form). a ...
- js的数据处理记录
mongoDB的mapReduce返回的数据有可能会非常之多,所以单独拎出来先在浏览器里面玩一玩; // 数据源 var arr = [ {"address": "四川汶 ...
- Tomcat处理HTTP请求源码分析(下)
转载:http://www.infoq.com/cn/articles/zh-tomcat-http-request-2 很多开源应用服务器都是集成tomcat作为web container的,而且对 ...
- 创业草堂之二十二:创业公司C类官员的职位说明书
麻雀虽小,五脏俱全. 创业公司启航,三五十来个人.七八条枪,其中“C”字开头的官儿还真少不了 – CEO.CTO.COO.CFO.CMO.CIO.CCO.CLO.Chairman/Chairwoman ...
- 87. Scramble String
题目: Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty subs ...
- Splunk常用命令
重启/查看状态/停止splunk [root@localhost splunk]# /opt/splunk/bin/splunk restart / status / stop
- servlet request.getParamter 有时获取参数为null
他妈的,参数有时可以获取,有时又不行,折腾了好久,把tomcat换成8.0的,之前用apache-tomcat-7.0.67
- [前端]利用a标签获取url里所需的内容
function parseURL(url) { var a = document.createElement('a'); a.href = url; return { source: url, pr ...