zoukankan      html  css  js  c++  java
  • 多线程,委托例子

    多线程:

    Type text here
        class ActiveDate
        
    {
            
    private string _CusID;
            
    private string _Visitor;
            
    private int _ShopNum;

            
    private int _flag = 0;

            
    public int Flag
            
    {
                
    get return _flag; }
                
    set { _flag = value; }
            }


            
    public string CusID
            
    {
                
    get return _CusID; }
                
    set { _CusID = value; }
            }


            
    public string Visitor
            
    {
                
    get return _Visitor; }
                
    set { _Visitor = value; }
            }


            
    public int ShopNum
            
    {
                
    get return _ShopNum; }
                
    set { _ShopNum = value; }
            }



            
    public void GetCustomerVisitor()
            
    {
                _Visitor 
    = DAL.CRM.Common.Customer.GetCustomerVisitor(_CusID);
                
    lock (this)
                
    {
                    _flag
    ++;
                }

            }


            
    public void GetCustomerShopNums()
            
    {
                _ShopNum 
    = Convert.ToInt32(DAL.CRM.Common.Customer.GetCustomerShopNum(_CusID));
                
    lock (this)
                
    {
                    _flag
    ++;
                }

            }

        }



                Module.CRM.Customer.CustomerActiveDate date 
    = new Module.CRM.Customer.CustomerActiveDate();

                ActiveDate ad 
    = new ActiveDate();
                ad.CusID 
    = customerID;

                Thread tr1 
    = new Thread(new ThreadStart(ad.GetCustomerVisitor));
                Thread tr2 
    = new Thread(new ThreadStart(ad.GetCustomerShopNums));

                tr1.Start();
                tr2.Start();

                
    while (true)
                
    {
                    
    if (ad.Flag == 2)
                    
    {
                        date.Visitor 
    = ad.Visitor;
                        date.ShopNum 
    = ad.ShopNum;
                        tr1.Abort();
                        tr2.Abort();
                        
    return date;
                    }

                }
    委托:
    delegate string myDelegate(String Name);
                myDelegate d1 
    = new myDelegate(DAL.CRM.Common.Customer.GetCustomerVisitor);
                myDelegate d2 
    = new myDelegate(DAL.CRM.Common.Customer.GetCustomerShopNum);

                IAsyncResult i1 
    = d1.BeginInvoke(customerID, nullnull);


                Module.CRM.Customer.CustomerActiveDate date 
    = new Module.CRM.Customer.CustomerActiveDate();

                IAsyncResult i2 
    = d2.BeginInvoke(customerID, nullnull);

                
    bool _flag = false;

                
    while (!_flag)
                
    {
                    _flag 
    = i1.IsCompleted && i2.IsCompleted;
                }


                date.Visitor 
    = d1.EndInvoke(i1);
                date.ShopNum 
    = Convert.ToInt32(d2.EndInvoke(i2));

                
    return date;
  • 相关阅读:
    app令牌的一个token实现
    velocity分页模板
    js基础-表单验证和提交
    做项目中没经验遇到的各种问题
    No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
    oracle创建用户
    oracle创建表相关
    pe创建激活administrator后消除问题,删除用户问题
    spring学习遇到的问题汇总
    .NET MVC自定义错误处理页面的方法
  • 原文地址:https://www.cnblogs.com/tommyli/p/922589.html
Copyright © 2011-2022 走看看