Skip to content

Commit

Permalink
Throw inner exception during running ImageProcessing.ParallelFor().
Browse files Browse the repository at this point in the history
  • Loading branch information
hamster620 committed Feb 1, 2024
1 parent 61a0543 commit 7840766
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions PixelViewer/Media/ImageProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,26 @@ public static ulong PackRgba64LE(ushort r, ushort g, ushort b, ushort a) =>
/// <param name="fromInclusive">Inclusive number which loop starts from.</param>
/// <param name="toExclusive">Exclusive number which loop ends to.</param>
/// <param name="body">Body of loop.</param>
public static void ParallelFor(int fromInclusive, int toExclusive, Action<int> body) =>
Parallel.For(fromInclusive, toExclusive, new ParallelOptions { MaxDegreeOfParallelism = MaxDegreeOfParallelism }, body);
public static void ParallelFor(int fromInclusive, int toExclusive, Action<int> body)
{
try
{
Parallel.For(fromInclusive, toExclusive, new ParallelOptions { MaxDegreeOfParallelism = MaxDegreeOfParallelism }, body);
}
catch (AggregateException ex)
{
var actualEx = default(Exception);
foreach (var innerEx in ex.InnerExceptions)
{
if (innerEx is TaskCanceledException)
throw new TaskCanceledException();
actualEx ??= innerEx;
}
if (actualEx is not null)
throw actualEx;
throw;
}
}


// Convert from RGB24 to Luminance based-on ITU-R BT.709.
Expand Down

0 comments on commit 7840766

Please sign in to comment.