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

  • 相关阅读:
    apache反向代理和负载均衡
    maven学习3,如何创建一个web项目
    初识maven及其安装步骤!!
    初识Eclipse!!
    登录页面!!!
    面向对象的三大要素
    【转载】fatal error C1010: unexpected end of file while looking for precompiled header directive
    C++ 读取XML 和TXT
    python +Libsvm 配置
    C++ 引用 和 指针 心得
  • 原文地址:https://www.cnblogs.com/jordan2009/p/2995056.html
Copyright © 2011-2022 走看看