且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在构造函数中调用异步方法?

更新时间:2022-12-14 08:03:35

***的解决方案是承认下载的异步性质并为其设计.

The best solution is to acknowledge the asynchronous nature of the download and design for it.

换句话说,决定您的应用程序在下载数据时应该是什么样子.让页面构造器设置那个视图,然后开始下载.下载完成后更新页面以显示数据.

In other words, decide what your application should look like while the data is downloading. Have the page constructor set up that view, and start the download. When the download completes update the page to display the data.

我有一篇关于 异步构造函数 的博客文章,您可能会觉得有用.此外,一些 MSDN 文章;一个关于 异步数据绑定(如果你使用的是 MVVM),另一个关于 异步***实践(即,您应该避免async void).

I have a blog post on asynchronous constructors that you may find useful. Also, some MSDN articles; one on asynchronous data-binding (if you're using MVVM) and another on asynchronous best practices (i.e., you should avoid async void).