From 62e92afae80c648a8018bde4e2b71a1ebe8de1d9 Mon Sep 17 00:00:00 2001 From: Dan Polivy Date: Thu, 26 Mar 2015 11:52:10 -0700 Subject: [PATCH] CB-8758 [wp8]: UnauthorizedAccessException on hide() When calling hide() from JS, the attempt to access Popup could happen on a background thread, which ends up throwing an UnauthorizedAccessException about cross-thread access. To address this, it's best to check the popup's state from within the UI thread. Fixes https://issues.apache.org/jira/browse/CB-8758 --- src/wp/SplashScreen.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/wp/SplashScreen.cs b/src/wp/SplashScreen.cs index feb4038..1c33c94 100644 --- a/src/wp/SplashScreen.cs +++ b/src/wp/SplashScreen.cs @@ -135,10 +135,9 @@ namespace WPCordovaClassLib.Cordova.Commands public void show(string options = null) { - - if (!popup.IsOpen) + Deployment.Current.Dispatcher.BeginInvoke(() => { - Deployment.Current.Dispatcher.BeginInvoke(() => + if (!popup.IsOpen) { popup.Child.Opacity = 0; @@ -162,17 +161,16 @@ namespace WPCordovaClassLib.Cordova.Commands { StartAutoHideTimer(); } - }); - } + } + }); } public void hide(string options = null) { - if (popup.IsOpen) + Deployment.Current.Dispatcher.BeginInvoke(() => { - Deployment.Current.Dispatcher.BeginInvoke(() => + if (popup.IsOpen) { - popup.Child.Opacity = 1.0; Storyboard story = new Storyboard(); @@ -191,8 +189,8 @@ namespace WPCordovaClassLib.Cordova.Commands popup.IsOpen = false; }; story.Begin(); - }); - } + } + }); } private void StartAutoHideTimer()