mono touch中,Async/Await 关键词应用举例
来源:互联网 发布:广告铃声制作软件 编辑:程序博客网 时间:2024/06/01 23:51
原文:http://docs.xamarin.com/guides/ios/user_interface/controls/part_2_-_working_with_the_ui_thread/
Async/Await Example
When using the C# 5 async/await keywords InvokeOnMainThread
is not required because when an awaited task completes the method continues on the calling thread.
This example code (which awaits on a Delay method call, purely for demonstration purposes) shows an async method that is called on the UI thread (it is a TouchUpInside handler). Because the containing method is called on the UI thread, UI operations like setting the text on a UILabel
or showing a UIAlertView
can be safely called after asynchronous operations have completed on background threads.
async partial void button2_TouchUpInside (UIButton sender){ textfield1.ResignFirstResponder (); textfield2.ResignFirstResponder (); textview1.ResignFirstResponder (); label1.Text = "async method started"; await Task.Delay(1000); // example purpose only label1.Text = "1 second passed"; await Task.Delay(2000); label1.Text = "2 more seconds passed"; await Task.Delay(1000); new UIAlertView("Async method complete", "This method", null, "Cancel", null) .Show(); label1.Text = "async method completed";}
If an async method is called from a background thread (not the main UI thread) then InvokeOnMainThread
would still be required.
- mono touch中,Async/Await 关键词应用举例
- Mono Touch Table应用
- React/Redux应用使用Async/Await
- ES6 async/await在项目中的应用
- await-async
- async await
- async/await
- async&await
- Async/Await
- async/await
- async/await
- async/await
- async/await
- async/await
- async/await
- async/await
- async/await
- async/await
- UVa:10717 Mint
- flume ng配置拓扑图
- Oracle Database Compression 1 - Basic Compression
- 从这段工作中学到的东西
- Linux2.6.37 I2C驱动框架分析(三)
- mono touch中,Async/Await 关键词应用举例
- MOSFET结构及其工作原理详解
- 51单片机——AT2402
- WWDC
- Js和C#中的字符串编码解码
- AFX_NOVTABLE与__declspec(novtable)
- busybox inittab文件分析
- 编程能力的四种境界
- Linux2.6.37 I2C驱动框架(四)