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

  • 相关阅读:
    poj1978
    poj3505
    免费专利讲座
    没有找到MFC80UD.DLL"没有找到MFC80UD.DLL,
    新手学C++/CLI及C#
    怎样激发技术人员的创新力?
    关于大型asp.net应用系统的架构—如何做到高性能高可伸缩性
    绝好的一套针对初学者的JavaScript教程
    VC如何将自身进程提升至管理员权限
    如何寻找优秀的专利代理人
  • 原文地址:https://www.cnblogs.com/jordan2009/p/2995056.html
Copyright © 2011-2022 走看看