zoukankan      html  css  js  c++  java
  • C#监听文件

    //全局变量 

    public static FileSystemWatcher Watcher;

           /// <summary>
            /// 设置监听配置
            /// </summary>
            /// <returns>ture/false</returns>
            public static Boolean SetMonitorFile()
            {
                try
                {
                    Watcher = new FileSystemWatcher();
                    Watcher.Filter = "*.txt";
                    Watcher.Path = "d:\"; //路径
                    Watcher.NotifyFilter = NotifyFilters.Size; //文件大小改变
                    //文件改变事件
                    Watcher.Changed += new FileSystemEventHandler(Watcher_Changed); ;
                    //文件创建事件       
                    Watcher.Created += new FileSystemEventHandler(Watcher_Created);
                    //文件删除事件
                    Watcher.Deleted += new FileSystemEventHandler(Watcher_Deleted);
                    //文件重命名事件
                    Watcher.Renamed += new RenamedEventHandler(Watcher_Renamed);
                    //设置监听子目录
                    Watcher.IncludeSubdirectories = false;
                    //开始进行监听(其实此处是标示是否进行事件监听和抛出)
                    Watcher.EnableRaisingEvents = true;
                    //watcher.EndInit();
                    return true;
                }
                catch (Exception ex)
                {
                    return false;
                }

            }

  • 相关阅读:
    Django数据库 相关之select_related/prefetch_related
    Django 序列化
    Django 信号
    Django缓存配置和使用
    Django FBV/CBV、中间件、GIT使用
    学员管理系统(SQLAlchemy 实现)
    Oracle的三种高可用集群方案
    linux系统安装硬盘分区建议
    Linux下expdp自动备份
    impdp导入报错ORA-39070:无法打开日志文件
  • 原文地址:https://www.cnblogs.com/-lxl/p/4843853.html
Copyright © 2011-2022 走看看