mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
Ensure ConfigureAwait(false) is set (#246)
Former-commit-id: e8df465ffa
This commit is contained in:
parent
8ba0d7deef
commit
aa30c82985
5 changed files with 22 additions and 19 deletions
|
@ -49,7 +49,7 @@ public async Task SerializeAsync(Stream stream, CancellationToken token)
|
|||
{
|
||||
var buffer = new byte[data.Stride * data.Height];
|
||||
Marshal.Copy(data.Scan0, buffer, 0, buffer.Length);
|
||||
await stream.WriteAsync(buffer, 0, buffer.Length, token);
|
||||
await stream.WriteAsync(buffer, 0, buffer.Length, token).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@ public void Serialize(Stream stream)
|
|||
|
||||
public async Task SerializeAsync(Stream stream, CancellationToken token)
|
||||
{
|
||||
await stream.WriteAsync(_sample, 0, _sample.Length, token);
|
||||
await stream.WriteAsync(_sample, 0, _sample.Length, token).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public async Task During(CancellationToken cancellationToken = default)
|
|||
{
|
||||
try
|
||||
{
|
||||
await ProcessDataAsync(cancellationToken);
|
||||
await ProcessDataAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
|
|
|
@ -50,7 +50,7 @@ public static async Task<bool> SnapshotAsync(string input, string output, Size?
|
|||
if (Path.GetExtension(output) != FileExtension.Png)
|
||||
output = Path.GetFileNameWithoutExtension(output) + FileExtension.Png;
|
||||
|
||||
var source = await FFProbe.AnalyseAsync(input);
|
||||
var source = await FFProbe.AnalyseAsync(input).ConfigureAwait(false);
|
||||
var (arguments, outputOptions) = BuildSnapshotArguments(input, source, size, captureTime, streamIndex, inputFileIndex);
|
||||
|
||||
return await arguments
|
||||
|
@ -93,7 +93,7 @@ public static Bitmap Snapshot(string input, Size? size = null, TimeSpan? capture
|
|||
/// <returns>Bitmap with the requested snapshot.</returns>
|
||||
public static async Task<Bitmap> SnapshotAsync(string input, Size? size = null, TimeSpan? captureTime = null, int? streamIndex = null, int inputFileIndex = 0)
|
||||
{
|
||||
var source = await FFProbe.AnalyseAsync(input);
|
||||
var source = await FFProbe.AnalyseAsync(input).ConfigureAwait(false);
|
||||
var (arguments, outputOptions) = BuildSnapshotArguments(input, source, size, captureTime, streamIndex, inputFileIndex);
|
||||
using var ms = new MemoryStream();
|
||||
|
||||
|
|
|
@ -75,13 +75,7 @@ void OnCancelEvent(object sender, int timeout)
|
|||
|
||||
try
|
||||
{
|
||||
_ffMpegArguments.Pre();
|
||||
Task.WaitAll(instance.FinishedRunning().ContinueWith(t =>
|
||||
{
|
||||
errorCode = t.Result;
|
||||
cancellationTokenSource.Cancel();
|
||||
_ffMpegArguments.Post();
|
||||
}), _ffMpegArguments.During(cancellationTokenSource.Token));
|
||||
errorCode = Process(instance, cancellationTokenSource).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -114,13 +108,7 @@ void OnCancelEvent(object sender, int timeout)
|
|||
|
||||
try
|
||||
{
|
||||
_ffMpegArguments.Pre();
|
||||
await Task.WhenAll(instance.FinishedRunning().ContinueWith(t =>
|
||||
{
|
||||
errorCode = t.Result;
|
||||
cancellationTokenSource.Cancel();
|
||||
_ffMpegArguments.Post();
|
||||
}), _ffMpegArguments.During(cancellationTokenSource.Token)).ConfigureAwait(false);
|
||||
errorCode = await Process(instance, cancellationTokenSource).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -134,6 +122,21 @@ await Task.WhenAll(instance.FinishedRunning().ContinueWith(t =>
|
|||
return HandleCompletion(throwOnError, errorCode, instance.ErrorData);
|
||||
}
|
||||
|
||||
private async Task<int> Process(Instance instance, CancellationTokenSource cancellationTokenSource)
|
||||
{
|
||||
var errorCode = -1;
|
||||
|
||||
_ffMpegArguments.Pre();
|
||||
await Task.WhenAll(instance.FinishedRunning().ContinueWith(t =>
|
||||
{
|
||||
errorCode = t.Result;
|
||||
cancellationTokenSource.Cancel();
|
||||
_ffMpegArguments.Post();
|
||||
}), _ffMpegArguments.During(cancellationTokenSource.Token)).ConfigureAwait(false);
|
||||
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
private bool HandleCompletion(bool throwOnError, int exitCode, IReadOnlyList<string> errorData)
|
||||
{
|
||||
if (throwOnError && exitCode != 0)
|
||||
|
|
Loading…
Reference in a new issue