• 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;//这个意思是不可在多线程中使用
            }
    
       
        }
    }
  • 相关阅读:
    The Snail
    Oil Deposits
    杭电3784(继续xxx定律)
    poj 2395 Out of Hay
    poj 2485 Highways(简单题)
    poj 2560 || 杭电1162
    Rescue
    “中国芯”能抗衡英特尔吗?
    2013,中国计算巨头放眼国际市场
    123063天两度瘫痪:为啥不在淘宝上卖火车票?
  • 原文地址:https://www.cnblogs.com/ruishuang208/p/3103106.html
Copyright © 2020-2023  润新知