• <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

            最新評論

            閱讀排行榜

            久久久噜噜噜久久中文字幕色伊伊| 久久91综合国产91久久精品| 婷婷综合久久狠狠色99h| 日韩精品无码久久一区二区三| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 久久水蜜桃亚洲av无码精品麻豆 | 国产激情久久久久影院| 亚洲色大成网站www久久九| 久久精品国产亚洲Aⅴ香蕉| 亚洲va久久久噜噜噜久久狠狠 | 99精品久久久久久久婷婷| 国产一久久香蕉国产线看观看| 久久久久亚洲爆乳少妇无| 人妻无码中文久久久久专区| 久久精品中文字幕一区| 欧美噜噜久久久XXX| 久久久精品国产亚洲成人满18免费网站 | 国产成人精品久久免费动漫| 人妻无码αv中文字幕久久琪琪布 人妻无码久久一区二区三区免费 人妻无码中文久久久久专区 | 国产成人香蕉久久久久| 久久亚洲国产成人精品性色| 无码精品久久一区二区三区| 91超碰碰碰碰久久久久久综合| 亚洲中文字幕久久精品无码APP| 久久精品中文字幕有码| 久久精品免费观看| a级成人毛片久久| 国产91久久精品一区二区| 久久天天躁狠狠躁夜夜躁2O2O | 日本三级久久网| 免费观看成人久久网免费观看| 中文字幕乱码人妻无码久久| 色播久久人人爽人人爽人人片aV| 精品国产91久久久久久久a| 婷婷久久综合九色综合九七| 久久亚洲国产精品一区二区| 国内精品伊人久久久久AV影院| 色综合久久精品中文字幕首页| 久久天堂AV综合合色蜜桃网| 久久精品无码午夜福利理论片| 热99re久久国超精品首页|