多线程监控文件夹,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 ...
随机推荐
- SystemInfo.deviceUniqueIdentifier 返回机器码
SystemInfo.deviceUniqueIdentifier 返回机器码
- SNAT
http://blog.chinaunix.net/uid-2628744-id-2454879.html
- *[hackerrank]Sam and sub-strings
https://www.hackerrank.com/contests/w3/challenges/sam-and-substrings DP.注意到以N[i]结尾的每个字符串的子数字和有规律: 53 ...
- ibaits与spring整合的心得
Ibatis2.3与spring3.0整合,其要明确一下,Ibatis与Hibernate一样都是dao层链接数据库用的框架.它是一个轻量级的orm框架,比Hibernate更加灵活. sqlMapC ...
- winserver2008,运行可执行文件,提示 激活上下文生成失败。 找不到从属程序集 Microsoft.VC90.DebugCRT,processorArchitecture="x86"
首先我运行的可执行文件是在win7下使用vs2008生成的release版本的文件,为什么在运行的时候提示需要DebugCRT? 另外我在winserver2008上是安装了vc2008的运行环境的. ...
- springmvc常用注解之@Controller和@RequestMapping
对于各种注解而言,排第一的当然是“@Controller”,表明某类是一个controller. “@RequestMapping”请求路径映射,如果标注在某个controller的类级别上,则表明访 ...
- 设计模式之工厂方法模式VS简单工厂方法模式
名词解释: 简单工厂:这个实在是没什么解释的,就是一个工厂类,然后有一个方法,根据传递的参数可以通过switch(你也可以是if,或者是使用高端的反射 )来进行对象的创建. 工厂方法:定义一个用于创建 ...
- 谷歌上不了?hoststool一键搞定host 支持在线更新
https://hosts.huhamhire.com/ http://serve.netsh.org/pub/ipv4-hosts/
- OpenRisc-52-run openrisc&orpmon on ml501 board
引言 之前关于openrisc的内容,几乎都是基于opencores官方的ordb2a那个开发板的,但是,实际情况是有那个板子的人不是很多,所以目前我在做一个与之类似的板子,并且很快就会跟大家见面,这 ...
- PHP5.4连接sqlserver
1.下载微软的php连接驱动:SQLSRV30.EXE(5.4对应,后面的native client要用2012)/SQLSRV20.EXE(5.3对应,native client要用2008)/SQ ...