Windows Phone:在 OnNavigatedTo 中调用异步方法 [英] Windows Phone: Call an Async method in OnNavigatedTo

查看:20
本文介绍了Windows Phone:在 OnNavigatedTo 中调用异步方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 WP8 应用程序中,我想在导航到页面时调用 Async 方法.

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

我想过将 OnNavigatedTo 方法用 async 关键字标记为如下所示:

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();
        }

是否有更好的方法来实现这一点,使用 async 标记 OnNavigatedTo 是否有问题?

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

推荐答案

不,这正是您应该做的.将 OnNavigatedTo 标记为异步,然后执行您需要执行的任何内容.

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

这篇关于Windows Phone:在 OnNavigatedTo 中调用异步方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆