FileSystemWatch使用示例

2021-09-09 03:58:37 字數 1550 閱讀 9455

msdn上一段關於使用filesystemwatch類的例子,今天寫的乙個功能使用到監視檔案系統的應用,看到這段**,很有啟發,留作紀念。**如下:

public class watcher

[permissionset(securityaction.demand, name="fulltrust")]

public static void run()

// create a new filesystemwatcher and set its properties.

filesystemwatcher watcher = new filesystemwatcher();

watcher.path = args[1];

/* watch for changes in lastaccess and lastwrite times, and

the renaming of files or directories. */

watcher.notifyfilter = notifyfilters.lastaccess | notifyfilters.lastwrite

| notifyfilters.filename | notifyfilters.directoryname;

watcher.includesubdirectories = true

; // 這個屬性用於指定是否監視指定目錄中的子目錄,很有用

// only watch text files.

watcher.filter = "*.*";

// add event handlers.

watcher.changed += new filesystemeventhandler(onchanged);

watcher.created += new filesystemeventhandler(onchanged);

watcher.deleted += new filesystemeventhandler(onchanged);

watcher.renamed += new renamedeventhandler(onrenamed);

// begin watching.

watcher.enableraisingevents = true;

// wait for the user to quit the program.

console.writeline("press /'q/' to quit the sample.");

while(console.read()!='q');

}// define the event handlers.

private static void onchanged(object source, filesystemeventargs e)

private static void onrenamed(object source, renamedeventargs e)

renamed to ", e.oldfullpath, e.fullpath);}}

**:

ConcurrentHashMap使用示例

concurrenthashmap是併發效率更高的map,用來替換其他執行緒安全的map容器,比如hashtable和collections.synchronizedmap。實際上,併發執行時,執行緒安全的容器只能保證自身的資料不被破壞,但無法保證業務的行為是否正確。錯誤的理解這裡的執行緒安全,不恰...

boost share ptr智慧型指標使用示例

12 3456 78910 1112 1314 1516 1718 1920 2122 2324 2526 2728 2930 3132 3334 3536 3738 3940 4142 4344 4546 4748 4950 5152 5354 5556 5758 5960 6162 6364 6...

sqlalchemy 的 Core 方式使用示例

知乎 sqlalchemy 的 core 方式運算元據是一種怎樣的體驗?答 爽!基本步驟如下 from sqlalchemy import create engine engine create engine sqlite memory echo true conn engine.connect f...