zoukankan      html  css  js  c++  java
  • winform控件跨线程委托

    1.

    this.listBox1.BeginInvoke(new Action(() =>
    {

    if (listBox1.Items.Count > 20)
    listBox1.Items.Clear();

    listBox1.Items.Add(DateTime.Now + " ," + i+", "+ dtsource.Rows[i]["ID"] + " ,执行完成!");
    listBox1.SelectedIndex = listBox1.Items.Count - 1;

    }));

    2.

    delegate void AddItemCallback(string text);
    private void AddItem(string text)
    {
    if (this.listBox1.InvokeRequired)
    {
    AddItemCallback d = new AddItemCallback(AddItem);
    this.listBox1.Invoke(d, new object[] { text });
    }
    else
    {
    if (this.listBox1.Items.Count > 100)
    listBox1.Items.Clear();
    this.listBox1.Items.Add(text);
    listBox1.SelectedIndex = listBox1.Items.Count - 1;
    }
    }

    3.

    listBox1.BeginInvoke(new del(Monitorlist), new object[] { DateTime.Now + ",采集" + Dmodels.SHOPNAME + "," + Dmodels.AREAS_BIG + "," + Dmodels.AREAS_SMALL + " ,完成!" });

    public void Monitorlist(string text)
    {
    if(this.listBox1.Items.Count>60)
    {
    this.listBox1.Items.Clear();
    }
    this.listBox1.Items.Add(text);
    this.listBox1.SelectedIndex = listBox1.Items.Count - 1;
    }

    4.

    public delegate void del2();

     this.label2.BeginInvoke(new del2(() => { this.label2.Text = dt.Rows[i]["aNAME"].ToString().Trim(); }));

  • 相关阅读:
    php 克隆和引用类
    php 抽象类、接口和构析方法
    php 面向对象之继承、多态和静态方法
    php封装练习
    php 面向对象之封装
    php 简单操作数据库
    php 练习
    用php输入表格内容
    php 指针遍历、预定义数组和常用函数
    php 数组定义、取值和遍历
  • 原文地址:https://www.cnblogs.com/ytup/p/5895998.html
Copyright © 2011-2022 走看看