Correctly Dispose Entrypoint Resources
This commit is contained in:
parent
b9b9e88765
commit
7fa73a1d3d
@ -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)
|
||||
|
@ -24,6 +24,7 @@ public class Entrypoint : IHostedService, IDisposable
|
||||
private readonly ILogger<Entrypoint> _logger;
|
||||
private readonly ILoggerFactory _loggerFactory;
|
||||
private Timer _queueTimer;
|
||||
private bool _disposed;
|
||||
private bool _analyzeAgain;
|
||||
private HashSet<Guid> _seasonsToAnalyze = new HashSet<Guid>();
|
||||
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
|
||||
/// <summary>
|
||||
/// Protected dispose.
|
||||
/// </summary>
|
||||
/// <param name="dispose">Dispose.</param>
|
||||
protected virtual void Dispose(bool dispose)
|
||||
/// <param name="disposing">Dispose.</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!dispose)
|
||||
if (!_disposed)
|
||||
{
|
||||
_queueTimer.Dispose();
|
||||
if (disposing)
|
||||
{
|
||||
_queueTimer.Dispose();
|
||||
_cancellationTokenSource?.Dispose();
|
||||
_autoTaskCompletEvent.Dispose();
|
||||
}
|
||||
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user