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
1 changed files with 19 additions and 21 deletions

View File

@ -164,35 +164,33 @@ namespace MediaBrowser.MediaEncoding.Attachments
WindowStyle = ProcessWindowStyle.Hidden,
ErrorDialog = false
};
var process = new Process
int exitCode;
using (var process = new Process { StartInfo = startInfo, EnableRaisingEvents = true })
{
StartInfo = startInfo,
EnableRaisingEvents = true
};
_logger.LogInformation("{File} {Arguments}", process.StartInfo.FileName, process.StartInfo.Arguments);
_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)
{
try
if (!ranToCompletion)
{
_logger.LogWarning("Killing ffmpeg attachment extraction process");
process.Kill();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error killing attachment extraction process");
try
{
_logger.LogWarning("Killing ffmpeg attachment extraction process");
process.Kill();
}
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;
if (exitCode != 0)