下载此文档

Async'ing Your Way to a essful App with :你的成功async'.pptx


文档分类:医学/心理学 | 页数:约48页 举报非法文档有奖
1/48
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/48 下载此文档
文档列表 文档介绍
Async void is only for top-level event handlers. Use the threadpool for CPU-bound code, but not IO-bound. Use pletionSource to wrap Tasks around events. Libraries shouldn't lie, and should be chunky. Key Takeaways Async void is only for event handlers User: “ It mostly works, but not 100% reliably. ” Diagnosis & Fix: Probably was using async void. Should return Task not void. For goodness ’ sake, stop using async void! Async void is only for event handlers private async void Button1_Click( object Sender, EventArgs e) { try { SendData ( "https://secure./services/ oauth / request_token " ); await Task .Delay (2000 ); DebugPrint ( "Received Data: " + m_GetResponse ); } catch ( Exception ex) { ( "Error posting data to server." + ); } } private async void SendData( string Url) { var request = WebRequest .Create ( Url ); using ( var response = await ()) using ( var stream = new StreamReader ( ())) m_GetResponse = (); } Async void is only for event handlers private async void Button1_Click( object Sender, EventArgs e ) { try { SendData ( "https://secure./services/ oauth / request_token " ); // await (2000); // DebugPrint ("Received Data: " + m_GetResponse ); } catch ( Exception ex) { ( "Error posting data to server." + ); } } private async void SendData( string Url) { var request = WebRequest .Create ( Url ); using ( var response = await ()) // exception on resumption using ( var stream = new StreamReader ( ())) m_GetResponse = (); } Async void is only for event handlers Principles Async void is a “ fire-and-forget ” mechanism... The caller is unable to know when an async void has finished The caller is unable to catch exceptions thrown from an async void (instead they get p

Async'ing Your Way to a essful App with :你的成功async' 来自淘豆网www.taodocs.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数48
  • 收藏数0 收藏
  • 顶次数0
  • 上传人薄荷牛奶
  • 文件大小0 KB
  • 时间2016-04-17