aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs')
-rw-r--r--MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs67
1 files changed, 32 insertions, 35 deletions
diff --git a/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs b/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs
index c530c9fd8..3f177a9fa 100644
--- a/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs
+++ b/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs
@@ -1,6 +1,6 @@
using System;
-using System.Diagnostics;
using System.Collections.Concurrent;
+using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
@@ -155,47 +155,44 @@ namespace MediaBrowser.MediaEncoding.Attachments
inputPath,
attachmentStreamIndex,
outputPath);
- var startInfo = new ProcessStartInfo
- {
- Arguments = processArgs,
- FileName = _mediaEncoder.EncoderPath,
- UseShellExecute = false,
- CreateNoWindow = true,
- WindowStyle = ProcessWindowStyle.Hidden,
- ErrorDialog = false
- };
- var process = new Process
- {
- StartInfo = startInfo
- };
- _logger.LogInformation("{File} {Arguments}", process.StartInfo.FileName, process.StartInfo.Arguments);
+ int exitCode;
- process.Start();
+ using (var process = new Process
+ {
+ StartInfo = new ProcessStartInfo
+ {
+ Arguments = processArgs,
+ FileName = _mediaEncoder.EncoderPath,
+ UseShellExecute = false,
+ CreateNoWindow = true,
+ WindowStyle = ProcessWindowStyle.Hidden,
+ ErrorDialog = false
+ },
+ EnableRaisingEvents = true
+ })
+ {
+ _logger.LogInformation("{File} {Arguments}", process.StartInfo.FileName, process.StartInfo.Arguments);
- var processTcs = new TaskCompletionSource<bool>();
- process.EnableRaisingEvents = true;
- process.Exited += (sender, args) => processTcs.TrySetResult(true);
- var unregister = cancellationToken.Register(() => processTcs.TrySetResult(process.HasExited));
- var ranToCompletion = await processTcs.Task.ConfigureAwait(false);
- unregister.Dispose();
+ process.Start();
- if (!ranToCompletion)
- {
- try
- {
- _logger.LogWarning("Killing ffmpeg attachment extraction process");
- process.Kill();
- }
- catch (Exception ex)
+ var ranToCompletion = await process.WaitForExitAsync(cancellationToken).ConfigureAwait(false);
+
+ if (!ranToCompletion)
{
- _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");
+ }
}
- }
- var exitCode = ranToCompletion ? process.ExitCode : -1;
-
- process.Dispose();
+ exitCode = ranToCompletion ? process.ExitCode : -1;
+ }
var failed = false;