等待导航pushasync吗? [英] await on navigation pushasync?

查看:151
本文介绍了等待导航pushasync吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xamarin表单中,导航方法,例如 PushAsync 是一个异步Task返回方法,但是它看起来在调用时使用await是否没有区别,对吗?我应该等待这些电话吗?

In Xamarin forms, the navigation methods such as PushAsync is a async Task returning method, but it looks whether using await when calling it makes no difference, is that right? Should I awaits these calls?

另一个问题,导航指南表示模型页面用于导航到需要先完成自包含任务的页面,然后将其关闭,但看起来pushasync和pushmodelasync没有什么区别,除了模型页面没有导航栏,用户仍然可以使用os后退按钮进行操作像pushasync一样返回,对吗?

Another question, the navigation guide says model pages are used for navigating to pages that requires finish self-contained tasks before dismissing it, but it looks it makes no difference between pushasync and pushmodelasync except for model pages there is no navigation bar, users can still use os back button to go back just like pushasync, is that right?

推荐答案

通常的注意事项在这里适用.如果您不await PushAsync,然后在代码中执行其他操作(或者您的框架执行了您可能不知道的其他操作),则这些操作可能在PushAsync完成之前执行(即-在页面创建之前).呈现给用户).另外,如果PushAsync操作中有一些异常-如果您不等待呼叫,您将不会注意到它.通常,即使您在PushAsync之后什么也不做-最好等待呼叫(与大多数其他异步操作一样),除非您知道为什么确实不想这样做.

Usual considerations with awating apply here. If you don't await PushAsync and then perform another actions in your code after that (or your framework performs another actions you might not be aware about) - those actions might be performed before PushAsync is finished (that is - before page is presented to user). Also, if there is some exception in PushAsync operation - you won't notice it if you don't await the call. In general, even if you don't do anything after PushAsync - it's better to await the call (as with most other async operations) unless you know why exactly you don't want to do that.

对于第二个问题,您的链接提供了答案:

As for second question, your link provides the answer:

在Android和Windows Phone上,用户始终可以返回到 通过按设备上的标准后退"按钮返回上一页.如果 模态页面要求用户完成一个独立的任务 离开页面之前,应用程序必须禁用后退"按钮. 这可以通过重写Page.OnBackButtonPressed来完成 模式页面上的方法.有关更多信息,请参见 Charles Petzold的Xamarin.Forms书.

On Android and Windows Phone, the user can always return to the previous page by pressing the standard Back button on the device. If the modal page requires the user to complete a self-contained task before leaving the page, the application must disable the Back button. This can be accomplished by overriding the Page.OnBackButtonPressed method on the modal page. For more information see Chapter 24 of Charles Petzold's Xamarin.Forms book.

这篇关于等待导航pushasync吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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