Convert AsyncCallback to awaitable task
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to implement the download of a given url. By the way my code is: private string url ; private StorageFile outputFile ; public void download () { HttpWebRequest request = HttpWebRequest . CreateHttp ( url ); request . BeginGetResponse ( new AsyncCallback ( playResponseAsync ), request ); } public async void playResponseAsync ( IAsyncResult asyncResult ) { //Declaration of variables HttpWebRequest webRequest = ( HttpWebRequest ) asyncResult . AsyncState ; try { using ( HttpWebResponse webResponse = ( HttpWebResponse )