Skip to content

Commit b65714d

Browse files
committed
Fixed a race condition that occurred when handling the cancellation of an asynchronous operation after the FFmpeg process had already exited. Fixes #348.
Related: #592
1 parent b3c201b commit b65714d

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,28 @@ private async Task<IProcessResult> Process(ProcessArguments processArguments, Ca
166166

167167
void OnCancelEvent(object sender, int timeout)
168168
{
169-
instance.SendInput("q");
169+
ExecuteIgnoringFinishedProcessExceptions(() => instance.SendInput("q"));
170170

171171
if (!cancellationTokenSource.Token.WaitHandle.WaitOne(timeout, true))
172172
{
173173
cancellationTokenSource.Cancel();
174-
instance.Kill();
174+
ExecuteIgnoringFinishedProcessExceptions(() => instance.Kill());
175+
}
176+
177+
static void ExecuteIgnoringFinishedProcessExceptions(Action action)
178+
{
179+
try
180+
{
181+
action();
182+
}
183+
catch (Instances.Exceptions.InstanceProcessAlreadyExitedException)
184+
{
185+
//ignore
186+
}
187+
catch (ObjectDisposedException)
188+
{
189+
//ignore
190+
}
175191
}
176192
}
177193

0 commit comments

Comments
 (0)