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(); }));

  • 相关阅读:
    51keil编译器printf函数
    asp.net里登陆记住密码
    Asp.net GridView分页
    DataTable拆分分页
    ASP.NET MVC 窗体身份验证及角色权限治理示例
    asp.net获取IP地址
    Asp.net Ajax框架教程
    将页面的ViewState放在Session
    20个Jquery表单插件
    前端下载图片的N种方法
  • 原文地址:https://www.cnblogs.com/ytup/p/5895998.html
Copyright © 2011-2022 走看看