首页 > 其他 > 详细

异步委托

时间:2016-06-13 17:11:00      阅读:128      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!