diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Analyzers/ChapterAnalyzer.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Analyzers/ChapterAnalyzer.cs index 1c1ac9a..ae6bdf6 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Analyzers/ChapterAnalyzer.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Analyzers/ChapterAnalyzer.cs @@ -89,17 +89,17 @@ public class ChapterAnalyzer : IMediaFileAnalyzer string expression, AnalysisMode mode) { - if (chapters.Count == 0) + var count = chapters.Count; + if (count == 0) { return null; } var config = Plugin.Instance?.Configuration ?? new PluginConfiguration(); - var count = chapters.Count; var reversed = mode != AnalysisMode.Introduction; - var (minDuration, maxDuration) = !reversed - ? (config.MinimumIntroDuration, config.MaximumIntroDuration) - : (config.MinimumCreditsDuration, config.MaximumCreditsDuration); + var (minDuration, maxDuration) = reversed + ? (config.MinimumCreditsDuration, config.MaximumCreditsDuration) + : (config.MinimumIntroDuration, config.MaximumIntroDuration); // Check all chapters for (int i = reversed ? count - 1 : 0; reversed ? i >= 0 : i < count; i += reversed ? -1 : 1) diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs index 169636c..818ded3 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs @@ -24,6 +24,7 @@ public class Entrypoint : IHostedService, IDisposable private readonly ILogger _logger; private readonly ILoggerFactory _loggerFactory; private Timer _queueTimer; + private bool _disposed; private bool _analyzeAgain; private HashSet _seasonsToAnalyze = new HashSet(); private static CancellationTokenSource? _cancellationTokenSource; @@ -111,13 +112,6 @@ public class Entrypoint : IHostedService, IDisposable // Stop the timer _queueTimer.Change(Timeout.Infinite, 0); - - if (_cancellationTokenSource != null) // Null Check - { - _cancellationTokenSource.Dispose(); - _cancellationTokenSource = null; - } - return Task.CompletedTask; } @@ -338,12 +332,19 @@ public class Entrypoint : IHostedService, IDisposable /// /// Protected dispose. /// - /// Dispose. - protected virtual void Dispose(bool dispose) + /// Dispose. + protected virtual void Dispose(bool disposing) { - if (!dispose) + if (!_disposed) { - _queueTimer.Dispose(); + if (disposing) + { + _queueTimer.Dispose(); + _cancellationTokenSource?.Dispose(); + _autoTaskCompletEvent.Dispose(); + } + + _disposed = true; } } }