zoukankan      html  css  js  c++  java
  • 在线程中修改窗体控件内容

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;

    namespace WindowsApplication2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
       
            //定义更新控件的方法
            public void updateLabel(string s)
            {

                this.label1.Text = s;
                this.label1.Refresh();         
            }

            //定义委托
            public delegate void dh(string s);
           
            //定义线程要调用的方法
            public void threadUpdate()
            {
                //实现委托
                dh dh1 = new dh(updateLabel);
                while (true)
                {
                    this.label1.Invoke(dh1, new object[] { "当前时间:"+DateTime.Now.ToString()+"."+DateTime.Now.Millisecond });
                }
            }

            //定义线程,并在线程中更新控件的内容
            Thread thd;
            private void button1_Click(object sender, EventArgs e)
            {
                thd = new Thread(new ThreadStart(threadUpdate));
                thd.Start();
            }

            private void button2_Click(object sender, EventArgs e)
            {
                thd.Abort();           
            }


        }
    }
  • 相关阅读:
    datasnap的监督功能【3】-TCP链接监督功能
    实体服务规则或值更新设置字段锁定性
    设置指定的单据视图
    启动或停止IIS
    SSMS2014清除登录记录
    未授予用户在此计算机上的请求登录类型
    采购合同手动下推采购订单提示没有NAME属性
    审批流消息中无法获取明细字段
    费用申请单反写费用合同提示第2行总金额超出,但是实际未超出
    调试手机端
  • 原文地址:https://www.cnblogs.com/baishahe/p/1077248.html
Copyright © 2011-2022 走看看