问题描述
在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:
这篇关于等待导航pushasync吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!