zoukankan      html  css  js  c++  java
  • 异步委托数据绑定!

    private void button1_Click(object sender, EventArgs e)
    {
        GetLogDelegate getLogDel = new GetLogDelegate(GetLogs);
       
        getLogDel.BeginInvoke(new AsyncCallback(LogTableCallBack),  null);
    }

    public delegate DataTable GetLogDelegate();

    /// <summary>
    /// 从数据库中获取操作日志,该操作耗费时间较长,
    /// 且返回数据量较大,日志记录可能超过万条。
    /// </summary>
    /// <returns></returns>
    private DataTable GetLogs()
    {
        string sql = "select * from ***";
        DataSet ds = new DataSet();

        using (OracleConnection cn = new OracleConnection(connectionString))
        {
            cn.Open();

            OracleCommand cmd = new OracleCommand(sql, cn);

            OracleDataAdapter adapter = new OracleDataAdapter(cmd);
            adapter.Fill(ds);
        }

        return ds.Tables[0];
    }

    /// <summary>
    /// 绑定日志到ListBox控件。
    /// </summary>
    /// <param name="tag"></param>
    private void LogTableCallBack(IAsyncResult tag)
    {
        AsyncResult result = (AsyncResult)tag;
        GetLogDelegate del = (GetLogDelegate)result.AsyncDelegate;

        DataTable logTable = del.EndInvoke(tag);

        if (this.listBox1.InvokeRequired)
        {
            this.listBox1.Invoke(new MethodInvoker(delegate()
            {
                BindLog(logTable);
            }));
        }
        else
        {
            BindLog(logTable);
        }
    }

    private void BindLog(DataTable logTable)
    {
        this.listBox1.DataSource = logTable;
    }

  • 相关阅读:
    [ Docker ] 基础安装使用及架构
    [ Docker ] 基础概念
    Nginx
    ELK
    SVN + Jenkins 构建自动部署
    Zabbix
    ELK
    ELK 部署文档
    vue.js在visual studio 2017下的安装
    vue.js是什么
  • 原文地址:https://www.cnblogs.com/jordan2009/p/2995056.html
Copyright © 2011-2022 走看看