I'm answering my own question now, but thanks to eX0du5 for pointing me to the right direction.
eX0du5 pointed out that void methods can't be awaited because they're not returning a Task. Searching for "Application_Launching returning Task" got me to a great msdn blog article that explained everything in detail:
The thing is: Event handlers can't return Tasks and the recommendation for calling async methods within app lifecycle event handlers is: "Don't."
Also, in the last paragraph of the blog article the author says that using .Wait()
on the async method might work, but it can deadlock when the UI thread gets the scheduler's attention.
So both issues I had with my two different approaches are explained. What to do now? eX0du5's suggestion (saving the Task instead of the data to the GlobalData
static class) is a workaround. In case the data that gets requested at the launch of the app needs to be accessed from different pages this seems like good solution, and in case the data is only needed on a page that doesn't get loaded after launching the app it even seems like a very good solution for prefetching data. I just checked that Tasks get executed when they get created and not only when awaited or used with .Result
or .Wait()
with this code.
For my purpose though, as I was only using the GlobalData
for using data in the MainPage.xaml.cs that gets loaded when launching the app, it seems to be less confusing and more concise to not use the Application_Launching
event handler alltogether and instead do everything in the OnNavigatedTo
event handler. That's where Noseratio's comment on my question comes in handy and also this question on SO: When should I load data in a Windows Phone 8 application? .