示例#1
0
        public async Task Start()
        {
            if (watcher != null)
            {
                throw new InvalidOperationException("Watcher already started");
            }

            UpdateActions();
            watcher = await StartNewWatcherAsync();
            UpdateActions();
        }
示例#2
0
 public void Stop()
 {
     if (watcher == null)
     {
         throw new InvalidOperationException("Watcher is not started");
     }
     if (watcher.IsStarted)
     {
         watcher.Stop();
     }
     watcher.Dispose();
     watcher = null;
 }
示例#3
0
 private Watcher StartNewWatcher()
 {
     var newWatcher = new Watcher();
     try
     {
         newWatcher.DirectoryPath = DirectoryPath;
         newWatcher.Filter = "*.log";
         newWatcher.LineWriter = CreateWriter();
         newWatcher.FileFound += WatcherFileFound;
         newWatcher.Start();
     }
     catch
     {
         try
         {
             newWatcher.Dispose();
         }
         catch
         {
         }
         throw;
     }
     return newWatcher;
 }