c#應用filesystemwatcher監督文件體系的變更。本站提示廣大學習愛好者:(c#應用filesystemwatcher監督文件體系的變更)文章只能為提供參考,不一定能成為您想要的結果。以下是c#應用filesystemwatcher監督文件體系的變更正文
#region 監督文件夾的變更
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = "f:\\";
watcher.NotifyFilter =//被監控的方面
NotifyFilters.LastWrite |
NotifyFilters.FileName |
NotifyFilters.DirectoryName;
// 定閱一些事宜,當它被觸發時(.net(windows)底層觸發它,我們不消管),履行我們的辦法
watcher.Changed += (object source, FileSystemEventArgs e) =>
{
Console.WriteLine("文件{0}曾經被修正,修正類型{1}", e.FullPath, e.ChangeType.ToString());
};
watcher.Created += (object source, FileSystemEventArgs e) =>
{
Console.WriteLine("文件{0}被樹立", e.FullPath);
};
watcher.Deleted += (object source, FileSystemEventArgs e) =>
{
Console.WriteLine("文件{0}曾經被刪除", e.FullPath);
};
watcher.Renamed += (object source, RenamedEventArgs e) =>
{
Console.WriteLine("文件{0}的稱號曾經從{1}釀成了{2}", e.OldFullPath, e.OldName, e.Name);
};
// 為true表現開啟FileSystemWatcher組件,反之我們的監控將不啟感化
watcher.EnableRaisingEvents = true;
#endregion
別的,告知年夜家一個 xor異或運算的應用技能,就是它可以在不引入第三個變量的情形下,瓜代兩個變量的值,你的變量可所以數值,也能夠是字符,假如是字符,我們須要應用它的hashcode值停止xor運算。
#region xor兩個變量交流
int a = 2;
int b = 3;
Console.WriteLine("a={0}", a);
Console.WriteLine("b={0}", b);
a = a ^ b ^ (b = a);
Console.WriteLine("a={0}", a);
Console.WriteLine("b={0}", b);
#endregion