首页 > 编程语言 > 详细

更新主窗口控件的内容1:子线程工作时同时更新主线程内的控件内容

时间:2014-03-25 19:05:01      阅读:453      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Windows.Forms;
 9 using System.Threading;
10 
11 namespace WindowsFormsApplication1
12 {
13     public partial class MainForm : Form
14     {
15         public MainForm()
16         {
17             InitializeComponent();
18         }
19 
20         delegate void SetMsg(string msg);
21         //private void SetMsgInfo(string msg)
22         //{
23         //    this.textBox1.Text = msg; 
24         //}
25 
26         private void button1_Click(object sender, EventArgs e)
27         {          
28             Thread thread = new Thread(M1);
29             thread.Start();
30         }
31 
32         void M1()
33         {
34             for (int i = 0; i < 10; i++)
35             {
36                 //this.Invoke(new SetMsg(SetMsgInfo), new object[] { i.ToString() });
37                 this.Invoke(new SetMsg((o) => { this.textBox1.Text = o; }), new object[] { i.ToString() });//匿名方法不懂的可以去查一下。
38                 Thread.Sleep(500);
39             }
40         }
41     }
42 }
bubuko.com,布布扣

更新主窗口控件的内容1:子线程工作时同时更新主线程内的控件内容,布布扣,bubuko.com

更新主窗口控件的内容1:子线程工作时同时更新主线程内的控件内容

原文:http://www.cnblogs.com/pnljs/p/3622958.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!