mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-14 01:55:45 +00:00
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
This commit is contained in:
parent
b3c201b42e
commit
f5ecbaee68
1 changed files with 18 additions and 2 deletions
|
|
@ -166,12 +166,28 @@ public class FFMpegArgumentProcessor
|
||||||
|
|
||||||
void OnCancelEvent(object sender, int timeout)
|
void OnCancelEvent(object sender, int timeout)
|
||||||
{
|
{
|
||||||
instance.SendInput("q");
|
ExecuteIgnoringFinishedProcessExceptions(() => instance.SendInput("q"));
|
||||||
|
|
||||||
if (!cancellationTokenSource.Token.WaitHandle.WaitOne(timeout, true))
|
if (!cancellationTokenSource.Token.WaitHandle.WaitOne(timeout, true))
|
||||||
{
|
{
|
||||||
cancellationTokenSource.Cancel();
|
cancellationTokenSource.Cancel();
|
||||||
instance.Kill();
|
ExecuteIgnoringFinishedProcessExceptions(() => instance.Kill());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ExecuteIgnoringFinishedProcessExceptions(Action action)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
action();
|
||||||
|
}
|
||||||
|
catch (Instances.Exceptions.InstanceProcessAlreadyExitedException)
|
||||||
|
{
|
||||||
|
//ignore
|
||||||
|
}
|
||||||
|
catch (ObjectDisposedException)
|
||||||
|
{
|
||||||
|
//ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue