public bool ProcessSynchronously(bool throwOnError = true, FFOptions?ffMpegOptions = null) { using var instance = PrepareInstance(ffMpegOptions ?? GlobalFFOptions.Current, out var cancellationTokenSource); var errorCode = -1; void OnCancelEvent(object sender, int timeout) { instance.SendInput("q"); if (!cancellationTokenSource.Token.WaitHandle.WaitOne(timeout, true)) { cancellationTokenSource.Cancel(); instance.Started = false; } } CancelEvent += OnCancelEvent; instance.Exited += delegate { cancellationTokenSource.Cancel(); }; try { _ffMpegArguments.Pre(); Task.WaitAll(instance.FinishedRunning().ContinueWith(t => { errorCode = t.Result; cancellationTokenSource.Cancel(); _ffMpegArguments.Post(); }), _ffMpegArguments.During(cancellationTokenSource.Token)); } catch (Exception e) { if (!HandleException(throwOnError, e, instance.ErrorData)) { return(false); } } finally { CancelEvent -= OnCancelEvent; } return(HandleCompletion(throwOnError, errorCode, instance.ErrorData)); }
public bool ProcessSynchronously(bool throwOnError = true) { using var instance = PrepareInstance(out var cancellationTokenSource); var errorCode = -1; void OnCancelEvent(object sender, EventArgs args) { instance?.SendInput("q"); cancellationTokenSource.Cancel(); } CancelEvent += OnCancelEvent; _ffMpegArguments.Pre(); try { Task.WaitAll(instance.FinishedRunning().ContinueWith(t => { errorCode = t.Result; cancellationTokenSource.Cancel(); }), _ffMpegArguments.During(cancellationTokenSource.Token)); } catch (Exception e) { if (!HandleException(throwOnError, e, instance.ErrorData)) { return(false); } } finally { CancelEvent -= OnCancelEvent; _ffMpegArguments.Post(); } return(HandleCompletion(throwOnError, errorCode, instance.ErrorData)); }