in my Windows 8.1 universal app I want to retrieve a local XML file on application start. But I'm confused with async / await. I use GetFileAsync, so it needs to be in an async function. But I could not call it from the initialization of the app. When I just call the function it says i need to add await. If I await, it says I could use await only in an async method, and therefore I could not do it in the initialization. So how could this be done? Many thanks!
Asked
Active
Viewed 59 times
1 Answers
1
See here: How to call asynchronous method from synchronous method in C#?
"If you have a simple asynchronous method that doesn't need to synchronize back to its context, then you can use Task.WaitAndUnwrapException"
So put the code into a separate method and use the method above or the second method RunTask.

Community
- 1
- 1

Joshua Dannemann
- 2,003
- 1
- 14
- 34