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);
} }
}请指教!
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);
} }
}请指教!
解决方案 »
- 如何调用类中正则表达方法来验证?
- 菜鸟求教 asp.net中用代码怎么对数据库进行简单的操作
- vs2008配色方案不能保存
- C# 可以重载New 运算符吗? 如果 用它实现 对象池呢?
- 请问联通SGIP1.2 如何下发wap push
- 有一个字段是“时间”字符型(如2005-8-6),有一个字段是“时间T”时间日期型。我想把所有的“时间”记录放在“时间T”记录里。怎么写SQL语句?
- 紧急求助
- ArraryList 对像序列化 与 反序列化 , 并将其存储进数据库的问题~~~~(帮帮我~)
- 在C#中listbox怎么用鼠标右键选中里边的项后,再弹出右键菜单。
- 在c#中有 VS STDIO 6。0 的Ms Comm 串口通讯控件么
- System.IO.File.Exists 和FileInfo类Exists 属性的区别?为何前者返回文件存在,后者返回不存在
- DataGridView存储数据
http://hi.baidu.com/84845357/blog/item/004f9d9289e77386a877a425.html