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 | |
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
-rw-r--r-- | Xamarin.Forms.Platform.WP8/TaskExtensions.cs | 33 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.WP8/WP8PlatformServices.cs | 2 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.WP8/Xamarin.Forms.Platform.WP8.csproj | 3 |
3 files changed, 36 insertions, 2 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 diff --git a/Xamarin.Forms.Platform.WP8/WP8PlatformServices.cs b/Xamarin.Forms.Platform.WP8/WP8PlatformServices.cs index c20071f4..4d49315e 100644 --- a/Xamarin.Forms.Platform.WP8/WP8PlatformServices.cs +++ b/Xamarin.Forms.Platform.WP8/WP8PlatformServices.cs @@ -134,7 +134,7 @@ namespace Xamarin.Forms public void OpenUriAction(Uri uri) { - Launcher.LaunchUriAsync(uri); + Launcher.LaunchUriAsync(uri).WatchForError(); } public void StartTimer(TimeSpan interval, Func<bool> callback) diff --git a/Xamarin.Forms.Platform.WP8/Xamarin.Forms.Platform.WP8.csproj b/Xamarin.Forms.Platform.WP8/Xamarin.Forms.Platform.WP8.csproj index d2e99c8a..c615ba4b 100644 --- a/Xamarin.Forms.Platform.WP8/Xamarin.Forms.Platform.WP8.csproj +++ b/Xamarin.Forms.Platform.WP8/Xamarin.Forms.Platform.WP8.csproj @@ -32,7 +32,7 @@ <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <NoWarn>4014;0618;0219</NoWarn> + <NoWarn>0618;0219</NoWarn> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> @@ -202,6 +202,7 @@ <DependentUpon>TableView.xaml</DependentUpon> </Compile> <Compile Include="TableViewRenderer.cs" /> + <Compile Include="TaskExtensions.cs" /> <Compile Include="TextAlignmentToHorizontalAlignmentConverter.cs" /> <Compile Include="TextCellRenderer.cs" /> <Compile Include="TimePickerRenderer.cs" /> |