From e6490de7ef64731f5d5d8533557843b234c2d5e3 Mon Sep 17 00:00:00 2001 From: Ian Randall Date: Fri, 25 Jan 2013 15:00:57 +1300 Subject: [PATCH 1/2] Update sample app with a mutha of a bug --- Sample/App.xaml.cs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/Sample/App.xaml.cs b/Sample/App.xaml.cs index aa233d8..abbc579 100644 --- a/Sample/App.xaml.cs +++ b/Sample/App.xaml.cs @@ -1,6 +1,10 @@ using System; +using System.Diagnostics; +using System.Threading; +using System.Threading.Tasks; using Windows.ApplicationModel; using Windows.ApplicationModel.Activation; +using Windows.Storage; using Windows.UI.Popups; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; @@ -58,12 +62,8 @@ private async void App_UnhandledException(object sender, Windows.UI.Xaml.Unhandl /// search results, and so forth. /// /// Details about the launch request and process. - protected override void OnLaunched(LaunchActivatedEventArgs args) + protected override async void OnLaunched(LaunchActivatedEventArgs args) { - // Start custom code - RegisterExceptionHandlingSynchronizationContext(); - // End custom code - Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, @@ -80,6 +80,12 @@ protected override void OnLaunched(LaunchActivatedEventArgs args) // Place the frame in the current Window Window.Current.Content = rootFrame; + + ExceptionHandlingSynchronizationContext + .RegisterForFrame(rootFrame) + .UnhandledException += SynchronizationContext_UnhandledException; + + await Test.LaunchAsync(); } if (rootFrame.Content == null) @@ -118,4 +124,17 @@ private void OnSuspending(object sender, SuspendingEventArgs e) deferral.Complete(); } } + + internal class Test + { + public static async Task LaunchAsync() + { + Debug.WriteLine("Before CreateFolderAsync: {0}", SynchronizationContext.Current); + await ApplicationData.Current.LocalFolder.CreateFolderAsync("cache", CreationCollisionOption.OpenIfExists); + Debug.WriteLine("After CreateFolderAsync:{0}", SynchronizationContext.Current); + + await Task.Yield(); + Debug.WriteLine("After Task.Yield: {0}", SynchronizationContext.Current); + } + } } From c49265811ba88378d2dc079055d2a713913700a3 Mon Sep 17 00:00:00 2001 From: Ian Randall Date: Fri, 25 Jan 2013 15:39:29 +1300 Subject: [PATCH 2/2] Move the call to Test.LaunchAsync() after Window.Current.Activate --- Sample/App.xaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sample/App.xaml.cs b/Sample/App.xaml.cs index abbc579..0af78d9 100644 --- a/Sample/App.xaml.cs +++ b/Sample/App.xaml.cs @@ -84,8 +84,6 @@ protected override async void OnLaunched(LaunchActivatedEventArgs args) ExceptionHandlingSynchronizationContext .RegisterForFrame(rootFrame) .UnhandledException += SynchronizationContext_UnhandledException; - - await Test.LaunchAsync(); } if (rootFrame.Content == null) @@ -100,6 +98,8 @@ protected override async void OnLaunched(LaunchActivatedEventArgs args) } // Ensure the current window is active Window.Current.Activate(); + + await Test.LaunchAsync(); } protected override void OnActivated(IActivatedEventArgs args)