• <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++ 基礎(chǔ)} {C++ 高級(jí)} {C#界面,C++核心算法} {設(shè)計(jì)模式} {C#基礎(chǔ)}

            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 夢(mèng)在天涯 閱讀(1271) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C#/.NET

            公告

            EMail:itech001#126.com

            導(dǎo)航

            統(tǒng)計(jì)

            • 隨筆 - 461
            • 文章 - 4
            • 評(píng)論 - 746
            • 引用 - 0

            常用鏈接

            隨筆分類

            隨筆檔案

            收藏夾

            Blogs

            c#(csharp)

            C++(cpp)

            Enlish

            Forums(bbs)

            My self

            Often go

            Useful Webs

            Xml/Uml/html

            搜索

            •  

            積分與排名

            • 積分 - 1808098
            • 排名 - 5

            最新評(píng)論

            閱讀排行榜

            伊人久久精品线影院| 亚洲人成伊人成综合网久久久| 99久久无色码中文字幕| 一本大道加勒比久久综合| 久久久久亚洲精品无码网址 | 久久精品国产一区二区三区| 久久精品国产精品亚洲下载| 久久午夜伦鲁片免费无码| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 久久久久久久久久久久久久| 9久久9久久精品| 日本WV一本一道久久香蕉| 97久久香蕉国产线看观看| 伊人久久大香线蕉精品不卡| 国产精品久久久久久福利漫画 | 国产精品一区二区久久精品涩爱| 久久99国产精品久久久| 中文字幕无码久久人妻| 国产福利电影一区二区三区久久久久成人精品综合 | 国产精品久久国产精麻豆99网站| 久久久久青草线蕉综合超碰| 97精品伊人久久久大香线蕉| 国产精品青草久久久久婷婷| 精产国品久久一二三产区区别| 国产午夜精品理论片久久 | 欧美精品一区二区久久| 日本精品久久久久中文字幕 | 久久精品成人| 久久久无码精品午夜| 久久精品无码专区免费| 久久国产免费直播| 久久精品不卡| 亚洲?V乱码久久精品蜜桃| 国产69精品久久久久9999| 色综合色天天久久婷婷基地| 国内精品久久久久影院一蜜桃| 久久久无码人妻精品无码| 久久棈精品久久久久久噜噜| 久久成人国产精品| 99久久99久久精品国产片| 欧美久久久久久精选9999|