Thursday, 5 September 2013

WinRT: Extended SplashScreen not awaiting async functions

WinRT: Extended SplashScreen not awaiting async functions

When my app is launched, several initialization tasks are executed.
Since the tasks could take a while, I would like to implement an extended
splash screen. I did so by following this How-To:
http://msdn.microsoft.com/en-us/library/windows/apps/hh868191.aspx
The extended splash screen is loaded and I can see the progress ring
animation. However, the splash is dismissed in the middle of performing
the initialization tasks instead waiting for them to complete.
That's my code in ExtendedSplashScreen.vb:
Public Sub New(splsCurrent As SplashScreen, bLoadState As Boolean)
InitializeComponent()
AddHandler Window.Current.SizeChanged, AddressOf ExtendedSplash_OnResize
Me.splsSplashScreen = splsCurrent
If Me.splsSplashScreen IsNot Nothing Then
AddHandler Me.splsSplashScreen.Dismissed, Async Sub(sender As
SplashScreen, e As Object)
bDismissed = True
Await
Me.cdDispatcher.RunAsync(CoreDispatcherPriority.Normal,
New
DispatchedHandler(Sub()
Me.frmRoot.Navigate(GetType(Main))
Window.Current.Content
=
Me.frmRoot
Window.Current.Activate()
End
Sub))
End Sub
Me.rectSplashImage = Me.splsSplashScreen.ImageLocation
Me.PositionImage()
End If
cdDispatcher = Window.Current.Dispatcher
Me.frmRoot = New Frame()
RestoreStateAsync(bLoadState)
End Sub
Public Async Sub RestoreStateAsync(bLoadState As Boolean)
If bLoadState Then
Await SuspensionManager.RestoreAsync()
End If
Await Me.InitializeData()
End Sub
And that's the init sub:
Private Async Function InitializeData() As Task
Me.tbProgress.Text = "initializing..."
Await InitializeDirs()
Me.tbProgress.Text = "loading images..."
Await LoadImageData()
Me.tbProgress.Text = "loading data..."
Await LoadXMLData()
Me.tbProgress.Text = "synchronizing data..."
Await Synchronize(True, True)
End Function
when I debug, I can see that up to Await LoadImageData() everything is
working just fine. But as soon as I step over that function, the splash
screen is dismissed and my first page is displayed. The rest of the splash
screen initializations are still executed though.
I also tried debugging the LoadImageData() function, but nothing seems
wrong in there. I have Awaits everywhere where needed.
Is there anything wrong in the code I posted, or do I have to dig deeper
in the awaited functions?

No comments:

Post a Comment