public Form1(CLIOption.Result opt) { this.cliOption = opt; InitializeComponent(); if (opt.Bulk) { throw new InvalidOperationException(); } Console.WriteLine("Mode: FileSystemWatcher"); fsWatcher.Path = opt.Directory; fsWatcher.Filter = "*"; fsWatcher.NotifyFilter = NotifyFilters.FileName; fsWatcher.IncludeSubdirectories = true; fsWatcher.Created += (Object sender, FileSystemEventArgs args) => { if (args.ChangeType == WatcherChangeTypes.Created) { if (Processor.IsImageExtension(args.FullPath)) { Console.WriteLine($"[Created] {args.FullPath}"); Processor.Process(opt, args.FullPath, (json) => { string text = json.responses[0].fullTextAnnotation.text; if (opt.Clipboard) { InvokeProperly(() => { try { ClipboardHelper.SetText(text); } catch (Exception ex) { Console.Error.WriteLine(ex.ToString()); } }); } if (opt.ShowResult) { try { System.Diagnostics.Process.Start(args.FullPath + ".html"); } catch (Exception ex) { Console.Error.WriteLine(ex.ToString()); } } if (opt.Notice) { InvokeProperly(() => { ShowBalloon(text, ToolTipIcon.Info, 5); }); } }); } } }; fsWatcher.EnableRaisingEvents = true; }