• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            C++ Programmer's Cookbook

            {C++ 基礎} {C++ 高級} {C#界面,C++核心算法} {設計模式} {C#基礎}

            Handle FileSystem Notifications with the FileSystemWatcher

            Author: James Foster Date Posted: 12/15/2001 .NET Version: 1.0.3705
            The FileSystemWatcher is a file system notification class. With this class, you can monitor a specific directory or file for changes, and be notified when the event occurs. In this article, we'll create a simple windows application that prints a message when text files in a specific path are accessed. The concepts presented here can be used for more complicated apps, such as a security monitoring tool for website changes, or perhaps an error handling procedure when an error log is written to the filesystem.

            Setting up the FileSystemWatcher is simple. Typically, you will follow these steps:

            1. Instantiate the FileSystemWatcher
            2. Set the Path to monitor
            3. Set any Filters
            4. Set your event handler
            The following code snippet shows the core of our sample application. As you can see, we first instantiate the FileSystemWatcher class in the System.IO namespace. Next we set the path to monitor, as well as the filters. Here, we are interested in text files being modified on the f: drive. We've defined an OnChanged method, and set this method as the EventHandler.

            public Form1()
            {
            ????//Required for Windows Form Designer support
            ????InitializeComponent();
            ????
            ????//Set up File Watcher
            ????System.IO.FileSystemWatcher watcher=new System.IO.FileSystemWatcher();
            ????watcher.Path = "f:\\";
            ????watcher.Filter ="*.txt";
            ????watcher.NotifyFilter = System.IO.NotifyFilters.LastWrite;
            ????watcher.EnableRaisingEvents =true;
            ????watcher.Changed +=new System.IO.FileSystemEventHandler(OnChanged);
            }
            ????
            privatevoid OnChanged(objectsender, System.IO.FileSystemEventArgs e)
            {
            ????textBox1.Text += e.Name.ToString()+" changed at "+ System.DateTime.Now.ToString();
            }
            C#VB

            When an event is fired, we use the FileSystemEventArgs to get the name of the file triggering the event, and display a message to the screen noting the time we learned of the event. The screenshot below shows our application in action:

            posted on 2006-04-14 12:45 夢在天涯 閱讀(1271) 評論(0)  編輯 收藏 引用 所屬分類: C#/.NET

            公告

            EMail:itech001#126.com

            導航

            統計

            • 隨筆 - 461
            • 文章 - 4
            • 評論 - 746
            • 引用 - 0

            常用鏈接

            隨筆分類

            隨筆檔案

            收藏夾

            Blogs

            c#(csharp)

            C++(cpp)

            Enlish

            Forums(bbs)

            My self

            Often go

            Useful Webs

            Xml/Uml/html

            搜索

            •  

            積分與排名

            • 積分 - 1807503
            • 排名 - 5

            最新評論

            閱讀排行榜

            久久97久久97精品免视看秋霞 | 国产成人精品综合久久久| 久久亚洲AV永久无码精品| 久久人与动人物a级毛片| 国产精品久久毛片完整版| 亚洲国产精品无码久久九九| 久久亚洲AV成人无码软件 | 久久精品成人免费国产片小草| 久久99精品国产麻豆宅宅| 99久久精品毛片免费播放| 久久精品这里只有精99品| 乱亲女H秽乱长久久久| 久久精品国产99久久久古代| 国产午夜精品理论片久久影视 | 国产精品久久久久蜜芽| 久久久国产精品福利免费| 久久久久亚洲av无码专区| 狠狠综合久久AV一区二区三区| 久久se精品一区精品二区| 精品久久久久久中文字幕大豆网| 久久99热精品| 丰满少妇人妻久久久久久| 色欲久久久天天天综合网| 色综合久久夜色精品国产| 亚洲一级Av无码毛片久久精品| 99精品久久精品一区二区| 亚洲精品乱码久久久久久蜜桃图片 | 无码国内精品久久人妻麻豆按摩| 91久久九九无码成人网站| 爱做久久久久久| 久久这里只有精品视频99| 久久精品一区二区国产| 久久久久亚洲av无码专区喷水| 久久无码高潮喷水| 久久久黄色大片| 国产精品久久久久久久人人看| 国产精品青草久久久久福利99| 久久99免费视频| 久久AⅤ人妻少妇嫩草影院| 99久久人人爽亚洲精品美女| 国产高清美女一级a毛片久久w|