private static void Main(string[] args) { var options = new Options(); if (CommandLine.Parser.Default.ParseArguments(args, options)) { // consume values here // Values are available here if (!string.IsNullOrEmpty(options.MonitorDirPath)) Console.WriteLine("MonitorDirPath: {0}", options.MonitorDirPath); mon = new Monitor(options); while (true) { Thread.Sleep(1000 * 1); } Console.ReadKey(); } }
public Monitor(Options options) { opt = options; seen = new Dictionary<string, DateTime>(); seenInterval = new TimeSpan(0,0, opt.PoolingInterval); watcher = new FileSystemWatcher(opt.MonitorDirPath, opt.TriggerName); watcher.IncludeSubdirectories = true; watcher.Created += (s, e) => { if (!seen.ContainsKey(e.FullPath) || (DateTime.Now - seen[e.FullPath]) > seenInterval) { seen[e.FullPath] = DateTime.Now; ThreadPool.QueueUserWorkItem( WaitForCreatingProcessToCloseFileThenDoStuff, e.FullPath); } }; watcher.EnableRaisingEvents = true; }