C# 文件监视程序事件触发

C# 文件监视程序事件触发,c#,filesystemwatcher,C#,Filesystemwatcher,我有一个方法如下 public void Run() { // Create a new FileSystemWatcher and set its properties. FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = "C:\\model_RCCMREC"; /* Watch for cha

我有一个方法如下

 public void Run()
        {
            // Create a new FileSystemWatcher and set its properties.
            FileSystemWatcher watcher = new FileSystemWatcher();
            watcher.Path = "C:\\model_RCCMREC";

            /* Watch for changes in LastAccess and LastWrite times, and
               the renaming of files or directories. */
            watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
            //   watch wav files.
            watcher.Filter = "*.wav";

            // Add event handlers. 
            watcher.Created += new FileSystemEventHandler(OnChanged);

            // Begin watching.
            watcher.EnableRaisingEvents = true;
        }
而Onchanged事件处理程序

public  void OnChanged(object source, FileSystemEventArgs e)
        {

//I AM DOING SOMETHNG HERE

}
我希望在每次将新文件添加到文件夹时都运行Onchanged事件处理程序。 为了模拟添加新文件,我做了一个测试方法

  public void test()
        { 

                File.Move(@"C:/TAKE_FORM_HERE_RCCM/59947874_59858856_03022013_074051_785_787_490_108.wav", @"C:/model_RCCMREC/59947874_59858856_03022013_074051_785_787_490_108.wav");

                 Run();

        }
但是,当我运行程序时,永远不会到达OnChanged事件处理程序

为什么会这样?或者我做错了什么?

试试这个

instead of using "created" Event use "Deleted" Event

watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);



OnChange will occur if any change occurs in that particular folder , 
First set a path and put a text file inside it and run your exe or web app 
then rename any file inside the folder so that your event will come
试试这个

instead of using "created" Event use "Deleted" Event

watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);



OnChange will occur if any change occurs in that particular folder , 
First set a path and put a text file inside it and run your exe or web app 
then rename any file inside the folder so that your event will come
试试这个

instead of using "created" Event use "Deleted" Event

watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);



OnChange will occur if any change occurs in that particular folder , 
First set a path and put a text file inside it and run your exe or web app 
then rename any file inside the folder so that your event will come
试试这个

instead of using "created" Event use "Deleted" Event

watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);



OnChange will occur if any change occurs in that particular folder , 
First set a path and put a text file inside it and run your exe or web app 
then rename any file inside the folder so that your event will come

您的问题是在初始化并启动FileSystemWatcher之前移动文件。要修复此调用,请先运行()


您的问题是在初始化并启动FileSystemWatcher之前移动文件。要修复此调用,请先运行()


您的问题是在初始化并启动FileSystemWatcher之前移动文件。要修复此调用,请先运行()


您的问题是在初始化并启动FileSystemWatcher之前移动文件。要修复此调用,请先运行()


问:为什么在这里标记asp.net?“文件监视程序”旨在在windows服务或windows窗体应用程序等充满状态的环境中运行。它并不意味着在asp.net这样的无状态环境中工作……问:为什么在这里标记asp.net?“文件监视程序”旨在在windows服务或windows窗体应用程序等充满状态的环境中运行。它并不意味着在asp.net这样的无状态环境中工作……问:为什么在这里标记asp.net?“文件监视程序”旨在在windows服务或windows窗体应用程序等充满状态的环境中运行。它并不意味着在asp.net这样的无状态环境中工作……问:为什么在这里标记asp.net?“文件监视程序”旨在在windows服务或windows窗体应用程序等充满状态的环境中运行。它并不意味着在asp.net这样的无状态环境中工作……没有仍然相同的结果@Aravind。我已经更新了我的答案@Anoushaka。。。。如果您正在调用Delete事件,那么它将出现在事件内部。因为您使用的是File.Move(),所以@Aravind没有仍然相同的结果。我已经更新了我的答案@Anoushaka。。。。如果您正在调用Delete事件,那么它将出现在事件内部。因为您使用的是File.Move(),所以@Aravind没有仍然相同的结果。我已经更新了我的答案@Anoushaka。。。。如果您正在调用Delete事件,那么它将出现在事件内部。因为您使用的是File.Move(),所以@Aravind没有仍然相同的结果。我已经更新了我的答案@Anoushaka。。。。如果您正在调用Delete事件,那么它将出现在事件内部。因为您正在使用File.Move()