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

            最新評論

            閱讀排行榜

            亚洲日本久久久午夜精品| 日产精品99久久久久久| 久久久久久国产精品美女| 人妻少妇精品久久| av无码久久久久不卡免费网站| 欧美综合天天夜夜久久| 国产精品99久久久精品无码 | 无码精品久久久久久人妻中字| 2021久久国自产拍精品| 日产精品久久久久久久| 狠狠久久综合| 麻豆精品久久精品色综合| 无码国内精品久久综合88| 国产精品va久久久久久久| 久久亚洲精精品中文字幕| 色青青草原桃花久久综合| 国产无套内射久久久国产| 99国产欧美久久久精品蜜芽| 色播久久人人爽人人爽人人片AV| 国产亚州精品女人久久久久久| 国产婷婷成人久久Av免费高清| 97视频久久久| 精品久久久一二三区| 久久99精品久久久久久野外| 久久免费精品视频| 91久久福利国产成人精品| 国产精品女同久久久久电影院| 无码人妻久久久一区二区三区 | 亚洲v国产v天堂a无码久久| 国产2021久久精品| 国产福利电影一区二区三区久久老子无码午夜伦不 | 青青青青久久精品国产| 蜜臀av性久久久久蜜臀aⅴ| 久久亚洲sm情趣捆绑调教| 欧美精品福利视频一区二区三区久久久精品 | 国产精品久久久久久久久免费| 少妇精品久久久一区二区三区| 麻豆av久久av盛宴av| 久久亚洲AV无码精品色午夜麻豆| 久久精品一区二区三区AV| 久久久久亚洲AV无码永不|