public async Task Start() { if (watcher != null) { throw new InvalidOperationException("Watcher already started"); } UpdateActions(); watcher = await StartNewWatcherAsync(); UpdateActions(); }
public void Stop() { if (watcher == null) { throw new InvalidOperationException("Watcher is not started"); } if (watcher.IsStarted) { watcher.Stop(); } watcher.Dispose(); watcher = null; }
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; }