标签:
线程内部无法直接调用web层控件的数据,以及线程与数据的相互交互,这时候要用到委托
代码:
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public delegate void wdelegate(string str1); //创建委托
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void DoWork()//实现功能
{
wdelegate mi = new wdelegate(UpdateForm);
this.BeginInvoke(mi, new Object[] { "我是文本框" });
}
public void UpdateForm(string param1) //给文本框赋值的方法
{
this.TextBox1.Text = param1;
}
private void button1_Click(object sender, EventArgs e)
{
Thread thread = new Thread(new ThreadStart(DoWork)); //线程
thread.Start();//开始线程
}
}
}
标签:
原文地址:http://www.cnblogs.com/coolTT/p/5242880.html