摘要:多執行緒的範例-收集
copy from : http://topic.csdn.net/u/20070722/12/16ce7f73-3b78-401a-93aa-989e4b91b7d9.html
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace jasper1983
{
delegate void ReportDelegate(string s);
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void ChangeTextBoxText(string s)
{
this.textBox1.Text = s;
}
private void button1_Click(object sender, EventArgs e)
{
ThreadClass tc = new ThreadClass(this);
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(tc.ThreadProc));
t.Start();
}
}
public class ThreadClass
{
private Form1 form;
public ThreadClass(Form1 form)
{
this.form = form;
}
public void ThreadProc()
{
for (int i = 0; i < 10; i++)
{
form.Invoke(new ReportDelegate(form.ChangeTextBoxText), new object[]{i.ToString()});
System.Threading.Thread.Sleep(1000);
}
}
}
}