Esempio n. 1
0
        private FileSystemWatcher MonitorDirectory(string path)
        {
            FileSystemWatcher fileSystemWatcher = new FileSystemWatcher();

            fileSystemWatcher.IncludeSubdirectories = false;
            fileSystemWatcher.Path                = path;
            fileSystemWatcher.Created            += new FileSystemEventHandler(FileSystemWatcher_Created);
            fileSystemWatcher.EnableRaisingEvents = true;
            if (WATCHER != null && !WATCHER.ContainsKey(path))
            {
                WATCHER.TryAdd(path, fileSystemWatcher);
            }
            fileSystemWatcher.WaitForChanged(WatcherChangeTypes.All);
            return(fileSystemWatcher);
        }
Esempio n. 2
0
        private FileSystemWatcher MonitorDirectory(string path)
        {
            FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(path);

            fileSystemWatcher.IncludeSubdirectories = false;
            //fileSystemWatcher.Path = path;

            fileSystemWatcher.NotifyFilter        = NotifyFilters.FileName | NotifyFilters.LastWrite;
            fileSystemWatcher.EnableRaisingEvents = true;

            //fileSystemWatcher.Created += FileSystemWatcher_Created;
            //fileSystemWatcher.Deleted += FileSystemWatcher_Deleted;
            fileSystemWatcher.Changed += FileSystemWatcher_Changed;
            //fileSystemWatcher.Renamed += FileSystemWatcher_Renamed;
            if (WATCHER != null && !WATCHER.ContainsKey(path))
            {
                WATCHER.TryAdd(path, fileSystemWatcher);
            }
            fileSystemWatcher.WaitForChanged(WatcherChangeTypes.All);
            return(fileSystemWatcher);
        }