public class MoveListen
{
public MoveListen()
{
//
//TODO: 在此处添加构造函数逻辑
//
} [STAThread]
public static void Main(string[] args)
{
//Run是监听方法
Thread.CurrentThread.Name = "ListenVideo";
Thread t = new Thread(new ThreadStart(Run));
t.Start();
Console.ReadLine();
}
..........
}
{
public MoveListen()
{
//
//TODO: 在此处添加构造函数逻辑
//
} [STAThread]
public static void Main(string[] args)
{
//Run是监听方法
Thread.CurrentThread.Name = "ListenVideo";
Thread t = new Thread(new ThreadStart(Run));
t.Start();
Console.ReadLine();
}
..........
}
while(true) 加入run中
/// 监听文件夹
/// </summary>
public static void Run()
{
// Create a new FileSystemWatcher and set its properties.
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = "E:\\Customer\\Upload\\file\\";
watcher.IncludeSubdirectories = true;
//监听类型
watcher.NotifyFilter = NotifyFilters.FileName;
//监听该文件夹中的所有文件
watcher.Filter = "*.*"; // 执行操作
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed); // 启用监听
watcher.EnableRaisingEvents = true; //// 等待用户退出
//Console.WriteLine("Press \'q\' to quit the sample.");
//while (Console.Read() != 'q') ;
}
因为你再run()里面少了一个while!!!
FileSystemWatcher 当前是局部变量, 有可能一出 RUN 就被释放了, 放到外面试下