Windows Phone: Call an Async method in OnNavigatedTo

折月煮酒 提交于 2019-12-22 05:18:54

问题


In my WP8 app, I want to call an Async method when the page is navigated to.

I thought about marking the OnNavigatedTo method with async keyword to be like this:

async protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            await myAsyncMethod();
        }

is there a better approach to achieve this, is there a problem in labeling OnNavigatedTo with async ?


回答1:


Nope this is exactly what you should be doing. Mark OnNavigatedTo as async and then execute whatever you need to execute.



来源:https://stackoverflow.com/questions/15064469/windows-phone-call-an-async-method-in-onnavigatedto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!