1 Star 3 Fork 1

BianChengNan / FileSystemWatcherEx

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

FileSystemWatcherEx

A simple enhanced class based on .net official FileSystemWatcher.

This class attempts to do something better

  • Try fire same event only one time, FileSystemWatcher may fire multiple times.
  • check whether file is ready for read write. FileSystemWatcher fire event immediately.
  • enhanced filter, support monitoring multiple extensions. As far as I know, FileSystemWatcher does not support.

Limitation

DO NOT keep the file open in your callback, open it and close it as soon as possible. then you should be safe.

I demonstrate a bad callback implementation in demo project. run it with -p option to see it.

Example usage

public void OnFileChanged(object sender, System.IO.FileSystemEventArgs e)
{
  if (e.ChangeType == System.IO.WatcherChangeTypes.Created 
     || e.ChangeType == System.IO.WatcherChangeTypes.Changed)
  {
    // do something.
  }
}

// monitor .bmp and .jpg and .png files and .docx files begin with a
var filters = "*.bmp|*.jpg|*.png|a*.docx";

var monitorPath = System.AppDomain.CurrentDomain.BaseDirectory;
var fileWatcherEx = new FileSystemWatcherEx(monitorPath
    , filters
    , true
    , ""
    , OnFileChanged
    , OnFileChanged
    , OnFileChanged
);

fileWatcherEx.Start();

// when finish monitoring

fileWatcherEx.Stop();

Demo Project

this demo project will monitor program directory recursively, and display changed .bmp file.

result

空文件

简介

增强版的 FileSystemWatcher 展开 收起
C# 等 2 种语言
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/bianchengnan/FileSystemWatcherEx.git
git@gitee.com:bianchengnan/FileSystemWatcherEx.git
bianchengnan
FileSystemWatcherEx
FileSystemWatcherEx
master

搜索帮助