首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET Framework >

小弟我是个老师,请各位帮忙看一下关于FileSystemWatcher的有关问题

2012-01-10 
我是个老师,请各位帮忙看一下关于FileSystemWatcher的问题。我的代码如下:static void Main(string[] args)

我是个老师,请各位帮忙看一下关于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);

}

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

热点排行