日期:2014-05-20  浏览次数:20910 次

我是个老师,请各位帮忙看一下关于FileSystemWatcher的问题。
我的代码如下:
  static void Main(string[] args)
  {
  FileSystemWatcher w = new FileSystemWatcher();
  string[] paths= System.Environment.GetCommandLineArgs();
  w.Path = @"c:\";
  w.EnableRaisingEvents = true;

  w.Created += new FileSystemEventHandler(w_Changed);
  w.Deleted += new FileSystemEventHandler(w_Changed);
  Console.ReadLine();
  }

  static void w_Changed(object sender, FileSystemEventArgs e)
  {
  //throw new Exception("The method or operation is not implemented.");
  Console.WriteLine("Directory changed{0}:{1}", e.ChangeType, e.FullPath);
  }


我想在才c盘下创建/删除文件夹,讲效果演示给学生看,可是无论怎么操作都看不到结果,设断点也不行,请各位大哥帮忙看一下是怎么回事?
我如何才能让学生看到监视的结果?

------解决方案--------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

public class A
{
public static void Main()
{
FileSystemWatcher w = new FileSystemWatcher();
string[] paths= System.Environment.GetCommandLineArgs();
w.Path = @"c:\";
w.EnableRaisingEvents = true;

w.Created += new FileSystemEventHandler(w_Changed);
w.Deleted += new FileSystemEventHandler(w_Changed);
Console.ReadLine();


static void w_Changed(object sender, FileSystemEventArgs e)
{
//throw new Exception("The method or operation is not implemented.");
Console.WriteLine("Directory changed{0}:{1}", e.ChangeType, e.FullPath);

}

这个代码可以用,我调试过了