Esempio n. 1
0
        public void Stop()
        {
            TODO.Clear();
            TODO = null;

            foreach (string path in WATCHER.Keys)
            {
                WATCHER[path].EnableRaisingEvents = false;
                WATCHER[path].Dispose();
                WATCHER[path] = null;
            }

            WATCHER.Clear();
            WATCHER = null;

            foreach (Task task in TASKS.Keys)
            {
                try
                {
                    TASKS[task].Cancel();
                    //task.Wait();
                    TASKS[task].Dispose();
                } catch (AggregateException ex)
                {
                    Console.WriteLine("Task cancel failed :( {0}", ex.InnerExceptions[0].Message);
                }
            }

            TASKS.Clear();
            TASKS = null;
        }
Esempio n. 2
0
        public void Stop()
        {
            _logger.LogInformation("otf stop request.");
            TODO.CollectionChanged -= Source_CollectionChanged;
            TODO.Clear();
            fsBag.Clear();
            foreach (string path in WATCHER.Keys)
            {
                WATCHER[path].EnableRaisingEvents = false;
                WATCHER[path].Dispose();
                WATCHER[path] = null;
            }

            WATCHER.Clear();
            WATCHER = null;

            foreach (Task task in TASKS.Keys)
            {
                try
                {
                    TASKS[task].Cancel();
                    //task.Wait();
                    TASKS[task].Dispose();
                }
                catch (AggregateException ex)
                {
                    _logger.LogError("Task cancel failed :( {0}", ex.InnerExceptions[0].Message);
                }
            }

            TASKS.Clear();
            TASKS   = null;
            Running = false;
            _logger.LogInformation("otf stop.");
        }
Esempio n. 3
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. 4
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);
        }