zoukankan      html  css  js  c++  java
  • 解决C#中FileSystemWatcher类的Changed事件触发多次的问题

    public static void WatchFile()
    {

    FileSystemWatcher watcher = new FileSystemWatcher();
    watcher.Path = "E:/Work/Test/source";
    watcher.Filter = "*.txt";
    watcher.NotifyFilter = NotifyFilters.Size;
    watcher.Changed += new FileSystemEventHandler(Change_Watch);
    watcher.EnableRaisingEvents = true;

    }

    public static void Change_Watch(object o, FileSystemEventArgs args)
    {
    string sourcePath = "E:/Work/Test/source/ceshi.txt";
    string targetPath = "E:/Work/Test/target/ceshi.txt";
    var watcher = o as FileSystemWatcher;
    watcher.EnableRaisingEvents = false;
    File.Copy(sourcePath, targetPath, true);
    watcher.EnableRaisingEvents = true;

    }

  • 相关阅读:
    博客园如何运行代码
    视觉差
    h5 播放器 -3
    播放器 视频 音频 -1
    游戏 保卫萝卜
    跟踪算法
    走口字

    联动日历
    jq 抽奖
  • 原文地址:https://www.cnblogs.com/sachem/p/6667120.html
Copyright © 2011-2022 走看看