Dispose of process correctly in AttachmentExtractor

This commit is contained in:
Mark Monteiro 2020-03-27 01:42:28 +01:00
parent 1c13be085f
commit d705931e81

View File

@ -164,35 +164,33 @@ namespace MediaBrowser.MediaEncoding.Attachments
WindowStyle = ProcessWindowStyle.Hidden, WindowStyle = ProcessWindowStyle.Hidden,
ErrorDialog = false ErrorDialog = false
}; };
var process = new Process
int exitCode;
using (var process = new Process { StartInfo = startInfo, EnableRaisingEvents = true })
{ {
StartInfo = startInfo, _logger.LogInformation("{File} {Arguments}", process.StartInfo.FileName, process.StartInfo.Arguments);
EnableRaisingEvents = true
};
_logger.LogInformation("{File} {Arguments}", process.StartInfo.FileName, process.StartInfo.Arguments); process.Start();
process.Start(); var ranToCompletion = await process.WaitForExitAsync(cancellationToken);
var ranToCompletion = await process.WaitForExitAsync(cancellationToken); if (!ranToCompletion)
if (!ranToCompletion)
{
try
{ {
_logger.LogWarning("Killing ffmpeg attachment extraction process"); try
process.Kill(); {
} _logger.LogWarning("Killing ffmpeg attachment extraction process");
catch (Exception ex) process.Kill();
{ }
_logger.LogError(ex, "Error killing attachment extraction process"); catch (Exception ex)
{
_logger.LogError(ex, "Error killing attachment extraction process");
}
} }
exitCode = ranToCompletion ? process.ExitCode : -1;
} }
var exitCode = ranToCompletion ? process.ExitCode : -1;
process.Dispose();
var failed = false; var failed = false;
if (exitCode != 0) if (exitCode != 0)