maui-linux/System.Maui.Platform.UAP/TaskExtensions.cs

34 строки
854 B
C#
Исходник Обычный вид История

2020-05-19 03:56:25 +03:00
using System;
2016-03-22 23:02:25 +03:00
using System.Threading;
using System.Threading.Tasks;
2020-05-19 03:56:25 +03:00
using global::Windows.Foundation;
2016-03-22 23:02:25 +03:00
2020-05-19 03:56:25 +03:00
namespace System.Maui.Platform.UWP
2016-03-22 23:02:25 +03:00
{
internal static class TaskExtensions
{
public static void WatchForError(this IAsyncAction self)
{
self.AsTask().WatchForError();
}
public static void WatchForError<T>(this IAsyncOperation<T> self)
{
self.AsTask().WatchForError();
}
public static void WatchForError(this Task self)
{
SynchronizationContext context = SynchronizationContext.Current;
if (context == null)
return;
self.ContinueWith(t =>
{
Exception exception = t.Exception.InnerExceptions.Count > 1 ? t.Exception : t.Exception.InnerException;
context.Post(e => { throw (Exception)e; }, exception);
}, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.Default);
}
}
}