zoukankan      html  css  js  c++  java
  • 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;//这个意思是不可在多线程中使用
            }
    
       
        }
    }
  • 相关阅读:
    WCF学习笔记
    下拉框层级绑定
    js在IE可以运行,在Firefox 不运行
    ajax 基础
    Asp.net Mvc Web Api 学习(一)
    阅读暗时间的笔记与心得
    阅读暗时间的心得与笔记
    阅读暗时间的笔记与心得(结束篇)
    阅读暗时间的笔记与心得
    阅读暗时间的心得与笔记
  • 原文地址:https://www.cnblogs.com/ruishuang208/p/3103106.html
Copyright © 2011-2022 走看看