zoukankan      html  css  js  c++  java
  • 异步线程

     //定义与方法同签名的委托
            private delegate void AL_DelegateName(List<AL_ProductList> finishedList, string sourceDir, string saveDir, bool jinYi, bool maoLian, bool product, bool FTP, DateTime dtStart, DateTime dtEnd, string name);
       private void AL_CallBackMethod(IAsyncResult ar)
            {
                //从异步状态ar.AsyncState中,获取委托对象
                AL_DelegateName dn = (AL_DelegateName)ar.AsyncState;
                //输出参数
                int i;
    
                //一定要EndInvoke,否则你的下场很惨
                dn.EndInvoke(ar);
                XtraMessageBox.Show("OK");
                //try
                //{
                //    this.pictureBox1.Visible = false;
                //}
                //catch (Exception)
                //{
    
                //    this.pictureBox1.Visible = false;
                //}
                //  MessageBox.Show("异步完成喽!i的值是" i.ToString() ",r的值是" r);
            }
    
    private void loadone()
    {
     #region
                    //实例化委托并初赋值
    
                    AL_DelegateName dn = new AL_DelegateName(new Actor.AliActor().ConvertMethod);
                    //输出参数
                    int i;
                    //实例化回调方法
                    //把AsyncCallback看成Delegate你就懂了,实际上AsyncCallback是一种特殊的Delegate,就像Event似的
                    AsyncCallback acb = new AsyncCallback(AL_CallBackMethod);
                    //pictureBox1.Visible = true;
                    //异步开始
                    //如果参数acb换成null则表示没有回调方法
                    //最后一个参数dn的地方,可以换成任意对象,该对象可以被回调方法从参数中获取出来,写成null也可以。参数dn相当于该线程的ID,如果有多个异步线程,可以都是null,但是绝对不能一样,不能是同一个object,否则异常
                    IAsyncResult iar = dn.BeginInvoke(finishedList, this.txtSourceDir.Text, this.txtSaveDir.Text, cktJinYi.Checked, cktProduct.Checked, cktMaoLian.Checked, ckFTP.Checked,
            dtStart, dtEnd, cbbSite.Text, acb, dn);
                    //去做别的事
    
                    #endregion   
    }
    
  • 相关阅读:
    安装WebStorm
    Could not obtain transaction-synchronized Session
    Hibernate4 No Session found for current thread原因
    Spring3系列7- 自动扫描组件或Bean
    论坛角色
    firefox浏览器无法显示bootstrap图标问题总结
    express文件上传中间件Multer最新使用说明
    判断圆和矩形是否相交C
    转化为用欧几里得算法判断互质的问题D
    (记录前面算过的后面仍然会用的数减小复杂度)A
  • 原文地址:https://www.cnblogs.com/guozhe/p/3064962.html
Copyright © 2011-2022 走看看