• <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++ 高級} {C#界面,C++核心算法} {設(shè)計模式} {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 夢在天涯 閱讀(1271) 評論(0)  編輯 收藏 引用 所屬分類: C#/.NET

            公告

            EMail:itech001#126.com

            導(dǎo)航

            統(tǒng)計

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

            常用鏈接

            隨筆分類

            隨筆檔案

            收藏夾

            Blogs

            c#(csharp)

            C++(cpp)

            Enlish

            Forums(bbs)

            My self

            Often go

            Useful Webs

            Xml/Uml/html

            搜索

            •  

            積分與排名

            • 積分 - 1808097
            • 排名 - 5

            最新評論

            閱讀排行榜

            欧美日韩精品久久久免费观看| 久久亚洲日韩精品一区二区三区| 欧美久久综合性欧美| 久久se精品一区二区影院| 久久久久18| 久久91精品国产91久久麻豆| 久久最新免费视频| 国产精品久久久福利| 亚洲精品国产第一综合99久久| 91视频国产91久久久| 国产精品成人久久久| 99久久国产免费福利| 久久精品一区二区三区AV| 91精品国产91久久| 精品无码久久久久久尤物| 亚洲国产精品综合久久网络| 久久99国产精品一区二区| 亚洲人成伊人成综合网久久久| 亚洲天堂久久精品| 国产精品久久久久久福利漫画| 亚洲精品国产第一综合99久久| 国产一区二区三精品久久久无广告 | 久久99免费视频| 亚洲AV无码久久| 久久精品成人欧美大片| 精品久久久久久久国产潘金莲| 国产2021久久精品| 亚洲综合久久综合激情久久| 99久久无码一区人妻a黑| 久久久久女人精品毛片| 欧美一区二区三区久久综合| 亚洲精品美女久久久久99| 国产激情久久久久久熟女老人| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 亚洲午夜无码久久久久| 精品国产乱码久久久久软件| 久久久久久噜噜精品免费直播| 久久这里只有精品视频99| 尹人香蕉久久99天天拍| 久久久久久精品免费看SSS| 精品国产99久久久久久麻豆|