Control.CheckForIllegalCrossThreadCalls = false不可在多线程中使用
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 WindowsFormsApplication16
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void MehtodOne()
{
for (int i = 0; i < 300; i++)
{
this.textBox1.Text += "************";
}
}
public void MethodTwo()
{
for (int i = 0; i < 300; i++)
{
this.textBox2.Text += "xxxxxxxxxxxxxxxxx";
}
}
//public delegate void ThreadStart();
private void button1_Click(object sender, EventArgs e)
{
#region "ThreadStart" 表示方法,在系统线程的线程执行 public delegate void ThreadStart();
// 摘要:
// Represents the method that executes on a System.Threading.Thread.
//表示方法,在系统线程的线程执行
//[ComVisible(true)]
//public delegate void ThreadStart();
#endregion
ThreadStart firstStart = this.MehtodOne;//调用 public void MehtodOne()
#region " Thread firstThread = new Thread(firstStart);"这句类似以下委托方法
//public class TestThread
// {
// ThreadStart s;
// public TestThread(ThreadStart start)
// {
// s = start;
// }
// public void Start()
// {
// s();
// }
// }
#endregion
Thread firstThread = new Thread(firstStart);
firstThread.Start();
//TestThread firstThread1 = new TestThread(firstStart);
//firstThread1.Start();
ThreadStart secondStart = this.MethodTwo; //调用 public void MethodTwo()
Thread secondThread = new Thread(secondStart);
secondThread.Start();
}
private void Form1_Load(object sender, EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;//这个意思是不可在多线程中使用
}
}
}