diff options
author | E.Z. Hart <hartez@users.noreply.github.com> | 2016-04-07 12:20:07 -0600 |
---|---|---|
committer | E.Z. Hart <hartez@users.noreply.github.com> | 2016-04-07 12:20:07 -0600 |
commit | e9eaacff4a1ee16729ae434d44fe0f9846712ef3 (patch) | |
tree | 227cc353cf00f2eadbb76909de9e5a929ab4e80b /Xamarin.Forms.Platform.WP8/TaskExtensions.cs | |
parent | 748153c4e1c13831dafb680841ca68ee2d071935 (diff) | |
download | xamarin-forms-e9eaacff4a1ee16729ae434d44fe0f9846712ef3.tar.gz xamarin-forms-e9eaacff4a1ee16729ae434d44fe0f9846712ef3.tar.bz2 xamarin-forms-e9eaacff4a1ee16729ae434d44fe0f9846712ef3.zip |
Merge pull request #60 from xamarin/warnings-WP8-4014
Turn off suppression of warning CS4014
Port TaskExtensions from WinRT projects to WP8
Update implementation of OpenUriAction to use TaskExtensions
Diffstat (limited to 'Xamarin.Forms.Platform.WP8/TaskExtensions.cs')
-rw-r--r-- | Xamarin.Forms.Platform.WP8/TaskExtensions.cs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WP8/TaskExtensions.cs b/Xamarin.Forms.Platform.WP8/TaskExtensions.cs new file mode 100644 index 00000000..51f275d7 --- /dev/null +++ b/Xamarin.Forms.Platform.WP8/TaskExtensions.cs @@ -0,0 +1,33 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using Windows.Foundation; + +namespace Xamarin.Forms +{ + 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); + } + } +}
\ No newline at end of file |