码迷,mamicode.com
首页 > 其他好文 > 详细

异步委托

时间:2016-06-13 17:13:48      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:

 1 using System;
 2 using System.Threading;
 3 using Telerik.WinControls;
 4 using System.Runtime.Remoting.Messaging;
 5 
 6 namespace TestForm
 7 {
 8     public partial class AsyncForm : Telerik.WinControls.UI.RadForm
 9     {
10         public AsyncForm()
11         {
12             InitializeComponent();
13             this.Load += AsyncForm_Load;
14         }
15 
16         void AsyncForm_Load(object sender, EventArgs e)
17         {
18             Action<string> ac = SetLabelText;
19             ac.BeginInvoke("hahaha", new AsyncCallback(CallBack), "AsyncState:Yes");
20         }
21 
22         private void CallBack(IAsyncResult ar)
23         {
24             string str = ar.AsyncState.ToString();//AsyncState:Yes
25             Action<string> ac = (Action<string>)((AsyncResult)ar).AsyncDelegate;
26             ac.EndInvoke(ar);
27         }
28 
29         private void SetLabelText(string text)
30         {
31             Thread.Sleep(2000);
32             this.Invoke(new Action(() => {
33                 radLabel1.Text = text;
34             }));
35         }
36     }
37 }

 

异步委托

标签:

原文地址:http://www.cnblogs.com/xingbinggong/p/5581171.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!