c# this.Invoke的定义及用法(个人理解的用法)
2012-11-04 20:00
459 查看
C# this.invoke()作用
Invoke()的作用是:在应用程序的主线程上执行指定的委托。一般应用:在辅助线程中修改UI线程( 主线程 )中对象的属性时,调用this.Invoke();using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; namespace Invoke_WindowsForm { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { Thread d = new Thread(new ThreadStart(this.DoSomething)); d.Start(); } private void DoSomething() { for (int i = 0; i < 100; i++) { this.Invoke(new MethodInvoker(() => { Thread.Sleep(100); this.label1.Text = i.ToString(); })); } } } }
以上代码就是动态改变UI上空间值得方法 主线程会在UI线程和辅助线程之间相互转换
相关文章推荐
- 转载:C# this.Invoke()的作用与用法 理解三
- C# this.Invoke()的作用与用法
- C# this.Invoke()的作用与用法
- C# this.Invoke()的作用与用法
- C# this.Invoke()的作用与用法
- C# this.Invoke()的作用与用法
- C# this.Invoke()的作用与用法
- 转载:C# this.invoke()作用 多线程操作UI 理解二
- C# this.Invoke()的作用与用法
- C#中简单的this与get的用法(string,decimal)
- c#中构造函数中this的用法
- C++中this指针的理解和用法
- C#中Invoke的用法
- C#中的索引器的简单理解和用法
- C# 泛型List的定义、作用、用法
- 个人理解c#对称加密 非对称加密 散列算法的应用场景
- C#中this的 四种 用法
- C#中winform隐藏启动窗体及this.invoke匿名函数
- C++中this指针的理解和用法
- 转:C# 对委托的BeginInvoke,EndInvoke 及Control 的BeginInvoke,EndInvoke 的理解