forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskExtensions.cs
34 lines (29 loc) · 851 Bytes
/
TaskExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Threading;
using System.Threading.Tasks;
using Windows.Foundation;
namespace Xamarin.Forms.Platform.UWP
{
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);
}
}
}