public void Stop() { FileWatcher.EnableRaisingEvents = false; if (DedupTask == null || DedupTask.IsCompleted) { return; } CancelSource.Cancel(); try { DedupTask?.Wait(); } catch (AggregateException exc) { exc.Handle(x => x is OperationCanceledException); } CancelSource?.Dispose(); OnStopped(); }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { CancelSource.Cancel(); try { DedupTask?.Wait(); } catch (AggregateException exc) { exc.Handle(x => x is OperationCanceledException); } CancelSource?.Dispose(); DedupTask?.Dispose(); FileWatcher?.Dispose(); // TODO: dispose managed state (managed objects) } disposedValue = true; } }