aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Monteiro <marknr.monteiro@protonmail.com>2020-03-27 01:53:08 +0100
committerMark Monteiro <marknr.monteiro@protonmail.com>2020-03-27 01:53:08 +0100
commit1f5caa46c53dde25ecf4482715333c049cb7e085 (patch)
tree3a5a79b89042d2252660b974f9de4ef4faf9477c
parentd705931e816db63b560efad51b8d0b79564aa260 (diff)
Fix some more issues with disposing Process instances
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs8
-rw-r--r--MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs94
2 files changed, 54 insertions, 48 deletions
diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
index 855b1c754..b3a45991e 100644
--- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
@@ -577,10 +577,10 @@ namespace MediaBrowser.MediaEncoding.Encoder
WindowStyle = ProcessWindowStyle.Hidden,
ErrorDialog = false,
};
- var process = new Process { StartInfo = processStartInfo, EnableRaisingEvents = true };
- _logger.LogDebug("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
+ _logger.LogDebug("{0} {1}", processStartInfo.FileName, processStartInfo.Arguments);
+ var process = new Process { StartInfo = processStartInfo, EnableRaisingEvents = true };
using (var processWrapper = new ProcessWrapper(process, this))
{
bool ranToCompletion;
@@ -706,14 +706,14 @@ namespace MediaBrowser.MediaEncoding.Encoder
WindowStyle = ProcessWindowStyle.Hidden,
ErrorDialog = false
};
- var process = new Process { StartInfo = processStartInfo, EnableRaisingEvents = true };
- _logger.LogInformation(process.StartInfo.FileName + " " + process.StartInfo.Arguments);
+ _logger.LogInformation(processStartInfo.FileName + " " + processStartInfo.Arguments);
await _thumbnailResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
bool ranToCompletion = false;
+ var process = new Process { StartInfo = processStartInfo, EnableRaisingEvents = true };
using (var processWrapper = new ProcessWrapper(process, this))
{
try
diff --git a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs
index f1f0bfeb1..a6982be5b 100644
--- a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs
+++ b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs
@@ -435,39 +435,42 @@ namespace MediaBrowser.MediaEncoding.Subtitles
WindowStyle = ProcessWindowStyle.Hidden,
ErrorDialog = false
};
- var process = new Process { StartInfo = processStartInfo, EnableRaisingEvents = true };
- process.Exited += (sender, args) => ((Process)sender).Dispose();
- _logger.LogInformation("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
+ int exitCode;
- try
- {
- process.Start();
- }
- catch (Exception ex)
+ using (var process = new Process { StartInfo = processStartInfo, EnableRaisingEvents = true })
{
- _logger.LogError(ex, "Error starting ffmpeg");
-
- throw;
- }
+ _logger.LogInformation("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
- var ranToCompletion = await process.WaitForExitAsync(TimeSpan.FromMinutes(5)).ConfigureAwait(false);
-
- if (!ranToCompletion)
- {
try
{
- _logger.LogInformation("Killing ffmpeg subtitle conversion process");
-
- process.Kill();
+ process.Start();
}
catch (Exception ex)
{
- _logger.LogError(ex, "Error killing subtitle conversion process");
+ _logger.LogError(ex, "Error starting ffmpeg");
+
+ throw;
}
- }
- var exitCode = ranToCompletion ? process.ExitCode : -1;
+ var ranToCompletion = await process.WaitForExitAsync(TimeSpan.FromMinutes(5)).ConfigureAwait(false);
+
+ if (!ranToCompletion)
+ {
+ try
+ {
+ _logger.LogInformation("Killing ffmpeg subtitle conversion process");
+
+ process.Kill();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error killing subtitle conversion process");
+ }
+ }
+
+ exitCode = ranToCompletion ? process.ExitCode : -1;
+ }
var failed = false;
@@ -583,39 +586,42 @@ namespace MediaBrowser.MediaEncoding.Subtitles
WindowStyle = ProcessWindowStyle.Hidden,
ErrorDialog = false
};
- var process = new Process { StartInfo = processStartInfo, EnableRaisingEvents = true };
- process.Exited += (sender, args) => ((Process)sender).Dispose();
- _logger.LogInformation("{File} {Arguments}", process.StartInfo.FileName, process.StartInfo.Arguments);
+ int exitCode;
- try
- {
- process.Start();
- }
- catch (Exception ex)
+ using (var process = new Process { StartInfo = processStartInfo, EnableRaisingEvents = true })
{
- _logger.LogError(ex, "Error starting ffmpeg");
-
- throw;
- }
+ _logger.LogInformation("{File} {Arguments}", process.StartInfo.FileName, process.StartInfo.Arguments);
- var ranToCompletion = await process.WaitForExitAsync(TimeSpan.FromMinutes(5)).ConfigureAwait(false);
-
- if (!ranToCompletion)
- {
try
{
- _logger.LogWarning("Killing ffmpeg subtitle extraction process");
-
- process.Kill();
+ process.Start();
}
catch (Exception ex)
{
- _logger.LogError(ex, "Error killing subtitle extraction process");
+ _logger.LogError(ex, "Error starting ffmpeg");
+
+ throw;
}
- }
- var exitCode = ranToCompletion ? process.ExitCode : -1;
+ var ranToCompletion = await process.WaitForExitAsync(TimeSpan.FromMinutes(5)).ConfigureAwait(false);
+
+ if (!ranToCompletion)
+ {
+ try
+ {
+ _logger.LogWarning("Killing ffmpeg subtitle extraction process");
+
+ process.Kill();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error killing subtitle extraction process");
+ }
+ }
+
+ exitCode = ranToCompletion ? process.ExitCode : -1;
+ }
var failed = false;