欢迎来到 IT实训基地-南通科迅教育
咨询电话:0513-81107100
C# 多线程传参和返回值委托异步回调实例
2017/1/20
科迅教育厅
339
南通Web前端培训机构,南通Web前端培训价格,南通Web前端培训费用大概多少钱

[csharp] 
       
 delegate bool MyDelete(TreeNodeCollection node); 
    bool prrelust = false; 
        bool xzjh = false; 
     bool prrelust = false; 
        bool xzjh = false; 
        public bool PrintTreeViewNode(TreeNodeCollection node) 
        { 
 
 
            foreach (TreeNode n in node) 
            { 
 
 
                if (n.Checked &&(Convert.ToInt32(n.Tag)==30 )) 
                { 
                    xzjh = true; 
                    string fanode = n.Parent.Parent.Text; 
                    string time = cbTimeDelay.Text.Trim().Substring(0, cbTimeDelay.Text.Trim().Length - 1); //延时  
                    int jihao = Convert.ToInt32(fanode.Substring(fanode.IndexOf("(") + 1, fanode.IndexOf(")") - fanode.IndexOf("(") - 1));//机号  
                    int menhao;//门号  
                    GCR.DoorSedBll bl = new GCR.DoorSedBll(); 
 
 
                    if (n.Parent.Text != "主机") 
                    { 
                        menhao = Convert.ToInt32(n.Parent.Tag) * 8 + 4 + n.Index; 
                    } 
                    else 
                    { 
                        menhao = n.Index;//门号  
                    } 
                    prrelust = bl.OpenDoorTimedelaySet(jihao, menhao, Convert.ToInt32(time)); 
 
 
 
 
 
 
                    if (!prrelust) 
                    { 
                        label3.Text = ""; 
                        break; 
                    } 
 
 
                } 
                PrintTreeViewNode(n.Nodes); 
            } 
 
 
 
 
            return prrelust; 
 
 
 
 
 
 
        } 
        #endregion 
 
 
  private void btOpenDoorTimeSet_Click(object sender, EventArgs e) 
        { 
            label3.Text = "延时加载中,请稍等......."; 
            MyDelete Dele = new MyDelete(PrintTreeViewNode); 
            Dele.BeginInvoke(this.tvDevc.Nodes, new AsyncCallback(AfterMyMothod), null); 
 
 
        } 
        #endregion 
 
 
        #region 异步传参回调函数  
        public void AfterMyMothod(IAsyncResult result) 
        { 
 
 
            AsyncResult async = (AsyncResult)result; 
            MyDelete DelegateInstance = (MyDelete)async.AsyncDelegate; 
            bool rt = DelegateInstance.EndInvoke(result); 
            if (xzjh) 
            { 
 
 
                if (rt) 
                { 
                    MessageBox.Show("延时加载成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
 
 
                } 
                else 
                { 
                    MessageBox.Show("延时加载失败!,请重新加载!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); 
 
 
                } 
            } 
            else 
            { 
 
 
                MessageBox.Show("请选择控制机号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); 
            } 
            label3.Text = ""; 
        } 
        #endregion 

     
 delegate bool MyDelete(TreeNodeCollection node);
    bool prrelust = false;
        bool xzjh = false;
     bool prrelust = false;
        bool xzjh = false;
        public bool PrintTreeViewNode(TreeNodeCollection node)
        {


            foreach (TreeNode n in node)
            {


                if (n.Checked &&(Convert.ToInt32(n.Tag)==30 ))
                {
                    xzjh = true;
                    string fanode = n.Parent.Parent.Text;
                    string time = cbTimeDelay.Text.Trim().Substring(0, cbTimeDelay.Text.Trim().Length - 1); //延时
                    int jihao = Convert.ToInt32(fanode.Substring(fanode.IndexOf("(") + 1, fanode.IndexOf(")") - fanode.IndexOf("(") - 1));//机号
                    int menhao;//门号
                    GCR.DoorSedBll bl = new GCR.DoorSedBll();


                    if (n.Parent.Text != "主机")
                    {
                        menhao = Convert.ToInt32(n.Parent.Tag) * 8 + 4 + n.Index;
                    }
                    else
                    {
                        menhao = n.Index;//门号
                    }
                    prrelust = bl.OpenDoorTimedelaySet(jihao, menhao, Convert.ToInt32(time));

 

 


                    if (!prrelust)
                    {
                        label3.Text = "";
                        break;
                    }


                }
                PrintTreeViewNode(n.Nodes);
            }

 


            return prrelust;

 

 


        }
        #endregion


  private void btOpenDoorTimeSet_Click(object sender, EventArgs e)
        {
            label3.Text = "延时加载中,请稍等.......";
            MyDelete Dele = new MyDelete(PrintTreeViewNode);
            Dele.BeginInvoke(this.tvDevc.Nodes, new AsyncCallback(AfterMyMothod), null);


        }
        #endregion


        #region 异步传参回调函数
        public void AfterMyMothod(IAsyncResult result)
        {


            AsyncResult async = (AsyncResult)result;
            MyDelete DelegateInstance = (MyDelete)async.AsyncDelegate;
            bool rt = DelegateInstance.EndInvoke(result);
            if (xzjh)
            {


                if (rt)
                {
                    MessageBox.Show("延时加载成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);


                }
                else
                {
                    MessageBox.Show("延时加载失败!,请重新加载!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);


                }
            }
            else
            {


                MessageBox.Show("请选择控制机号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            label3.Text = "";
        }
        #endregion

77
关闭
先学习,后交费申请表
每期5位名额
在线咨询
免费电话
QQ联系
先学习,后交费
TOP
您好,您想咨询哪门课程呢?
关于我们
机构简介
官方资讯
地理位置
联系我们
0513-91107100
周一至周六     8:30-21:00
微信扫我送教程
手机端访问
南通科迅教育信息咨询有限公司     苏ICP备15009282号     联系地址:江苏省南通市人民中路23-6号新亚大厦三楼             法律顾问:江苏瑞慈律师事务所     Copyright 2008-