本文介绍了如何在C#中使用Filewatcher的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经为filewatcher创建了一个程序,但是虽然我在window应用程序中理解了它,但是却无法在控制台应用程序中理解它.
I have created a program for filewatcher but not able to understand it in console application though i understood it in window application.
namespace fsw_watcher { class Program { static void Main(string[] args) { FileSystemWatcher fsw = new FileSystemWatcher (Environment.GetEnvironmentVariable("USERPROFILE")); fsw.IncludeSubdirectories = true; fsw.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite; fsw.Created += new FileSystemEventHandler(fsw_created); fsw.Deleted += new FileSystemEventHandler(fsw_deleted); fsw.Renamed += new RenamedEventHandler(fsw_Renamed); fsw.Changed += new FileSystemEventHandler(fsw_Changed); fsw.EnableRaisingEvents = true; Console.WriteLine("Press a key to end the program."); Console.ReadKey(); } static void fsw_created(object sender, FileSystemEventArgs e) { Console.WriteLine("created"+ e.FullPath); } static void fsw_deleted(object sender, FileSystemEventArgs e) { Console.WriteLine("deleted" + e.FullPath); } static void fsw_Changed(object sender, FileSystemEventArgs e) { Console.WriteLine(e.ChangeType + ": " + e.FullPath); } static void fsw_Renamed(object sender, RenamedEventArgs e) { Console.WriteLine(e.ChangeType + " from " + e.OldFullPath + " to " + e.Name); } } }以窗口形式,我能够给出路径并可以在那里监视,但是在这里我无法找到给出路径的位置. 因此,如果有人可以帮助我. 谢谢 问候
in window form i was able to give path and could monitor there but here i am not able to locate where to give path. So if anybody could help me in this . thanks regards
推荐答案C#中的File Watcher Windows [ ^ ] www.c-sharpcorner/uploadfile/puranindia/filesystemwatcher-in -C-Sharp/ [ ^ ] File Watcher Windows in C#[^] www.c-sharpcorner/uploadfile/puranindia/filesystemwatcher-in-C-Sharp/[^]
更多推荐
如何在C#中使用Filewatcher
发布评论