zoukankan      html  css  js  c++  java
  • FileSystemWatcher.cs

    /*
     * C# Programmers Pocket Consultant
     * Author: Gregory S. MacBeth
     * Email: gmacbeth@comporium.net
     * Create Date: June 27, 2003
     * Last Modified Date:
     * Version: 1
     */
    using System;
    using System.IO;

    namespace Client.Chapter_11___File_and_Streams
    {
        public class Test
        {
            public static void Main(string[] args)
            {
                 FileSystemWatcher watcher = new FileSystemWatcher();
                 watcher.Path = @"c:\Test";
                 watcher.NotifyFilter  =
                                                        NotifyFilters.LastAccess |
                                                        NotifyFilters.LastWrite |
                                                        NotifyFilters.FileName |
                                                        NotifyFilters.DirectoryName;
                 watcher.Filter = "*.txt";
                 watcher.Changed += new FileSystemEventHandler(OnChanged);
                 watcher.Created += new FileSystemEventHandler(OnChanged);
                 watcher.Deleted += new FileSystemEventHandler(OnChanged);
                 watcher.Renamed += new RenamedEventHandler(OnRenamed);
                 watcher.EnableRaisingEvents = true;
                             
            }
            
            public static void OnChanged(object source, FileSystemEventArgs e)
            {
                   Console.WriteLine("Event Fired");
            }
            public static void OnRenamed(object source, RenamedEventArgs e)
            {
                Console.WriteLine("Event Fired");
            }
        
        }
    }
  • 相关阅读:
    继承人人前端笔试题
    【转】ASP.NET应用程序生命周期趣谈
    C#中正则表达式的高级应用
    使用C#导入导出数据到Excel
    Server.Transfer详细解释
    防止刷新重复post提交
    程序只运行一次的方法
    注释很全的抽象工厂(没用简单工厂优化)
    利用反射动态调用类成员C#
    编程经历的一些思考
  • 原文地址:https://www.cnblogs.com/shihao/p/2501876.html
Copyright © 2011-2022 走看看