zoukankan      html  css  js  c++  java
  • 多线程和委托简单例子

     private void btnRun_Click(object sender, EventArgs e)
            {
                Thread th = new Thread(new ThreadStart(heating));
                th.IsBackground = true;
                th.Start();
               
            }
            int templeture;
            delegate void DisplayHandler(string tempStr);
          
            protected void heating()
            {

                for (int i = 0; i < 100; i++)
                {
                    templeture = i;
                    string tp = i.ToString();
                    //this.Invoke(new DisplayHandler(Displaytemp));//这里是不带参数
                    this.BeginInvoke(new DisplayHandler(Displaytemp), tp);//带参数据
                    Thread.Sleep(1000);

                }
            }
            protected void Displaytemp(string tempStr)
            {

                this.label1.Text = tempStr;// templeture.ToString();
            }

    -------长沙程序员技术交流QQ群:428755207-------
  • 相关阅读:
    Python: 通过 pip 安装第三方包后依然不能 import
    jar命令
    vim中删除^M
    Linux 非互联网环境安装依赖包
    安装rpm包时提示错误:依赖检测失败的解决方法
    python3.5安装
    yum配置安装 及报错
    统计数组元素出现的次数
    插入法排序
    选择法排序
  • 原文地址:https://www.cnblogs.com/qq4004229/p/2135829.html
Copyright © 2011-2022 走看看