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];
|
var buffer = new byte[data.Stride * data.Height];
|
||||||
Marshal.Copy(data.Scan0, buffer, 0, buffer.Length);
|
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
|
finally
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,7 +24,7 @@ public void Serialize(Stream stream)
|
||||||
|
|
||||||
public async Task SerializeAsync(Stream stream, CancellationToken token)
|
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
|
try
|
||||||
{
|
{
|
||||||
await ProcessDataAsync(cancellationToken);
|
await ProcessDataAsync(cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (TaskCanceledException)
|
catch (TaskCanceledException)
|
||||||
{
|
{
|
||||||
|
|
|
@ -50,7 +50,7 @@ public static async Task<bool> SnapshotAsync(string input, string output, Size?
|
||||||
if (Path.GetExtension(output) != FileExtension.Png)
|
if (Path.GetExtension(output) != FileExtension.Png)
|
||||||
output = Path.GetFileNameWithoutExtension(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);
|
var (arguments, outputOptions) = BuildSnapshotArguments(input, source, size, captureTime, streamIndex, inputFileIndex);
|
||||||
|
|
||||||
return await arguments
|
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>
|
/// <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)
|
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);
|
var (arguments, outputOptions) = BuildSnapshotArguments(input, source, size, captureTime, streamIndex, inputFileIndex);
|
||||||
using var ms = new MemoryStream();
|
using var ms = new MemoryStream();
|
||||||
|
|
||||||
|
|
|
@ -75,13 +75,7 @@ void OnCancelEvent(object sender, int timeout)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_ffMpegArguments.Pre();
|
errorCode = Process(instance, cancellationTokenSource).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||||
Task.WaitAll(instance.FinishedRunning().ContinueWith(t =>
|
|
||||||
{
|
|
||||||
errorCode = t.Result;
|
|
||||||
cancellationTokenSource.Cancel();
|
|
||||||
_ffMpegArguments.Post();
|
|
||||||
}), _ffMpegArguments.During(cancellationTokenSource.Token));
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -114,13 +108,7 @@ void OnCancelEvent(object sender, int timeout)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_ffMpegArguments.Pre();
|
errorCode = await Process(instance, cancellationTokenSource).ConfigureAwait(false);
|
||||||
await Task.WhenAll(instance.FinishedRunning().ContinueWith(t =>
|
|
||||||
{
|
|
||||||
errorCode = t.Result;
|
|
||||||
cancellationTokenSource.Cancel();
|
|
||||||
_ffMpegArguments.Post();
|
|
||||||
}), _ffMpegArguments.During(cancellationTokenSource.Token)).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -134,6 +122,21 @@ await Task.WhenAll(instance.FinishedRunning().ContinueWith(t =>
|
||||||
return HandleCompletion(throwOnError, errorCode, instance.ErrorData);
|
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)
|
private bool HandleCompletion(bool throwOnError, int exitCode, IReadOnlyList<string> errorData)
|
||||||
{
|
{
|
||||||
if (throwOnError && exitCode != 0)
|
if (throwOnError && exitCode != 0)
|
||||||
|
|
Loading…
Reference in a new issue