0

私は次のような方法を持っています

 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 イベント ハンドラに到達しません。

なぜそうなのですか?または私は何を間違っていますか?

4

2 に答える 2

0

これを試して

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
于 2013-10-29T07:15:09.993 に答える