线程概念WaitHandle []执行错误

时间:2015-10-29 10:52:16

标签: xml multithreading web-services

我是新线程概念我在我的代码中应用线程概念当我运行逻辑时我有两个beigninvoke概念当我执行它传递两个beigninvoke然后它将获得输出或者它只执行一个beigninvoke意味着它将不会得到输出它会在WaitHandle []中得到错误,因为另一个线程将在null中传递,我该如何解决这个问题

  [WebMethod]
  public XmlDocument GIHotelInventory(string GIMonth, string GIYear, string username)
    {
        XmlDocument Ctxml = new XmlDocument();
        XmlDocument Mmtxml = new XmlDocument();
        XmlDocument xml = new XmlDocument();

        var dt = ProviderDetails(username);

        CtCaller ct = new CtCaller(*****Inventory);
        MmtCaller mmt = new MmtCaller(*****Inventory);
        IAsyncResult ctreslt = null;
        IAsyncResult mmtreslt = null;
        string ProviderUserName = string.Empty;
        string ProviderPassword = string.Empty;
        foreach (DataRow a in dt.Rows)
        {
            CollectionProviderDetails prd = new CollectionProviderDetails();
            prd.GiUserName = Convert.ToString(a["GiUserName"]);
            prd.ProviderName = Convert.ToString(a["ProviderName"]);
            ProviderUserName = Convert.ToString(a["PrUserName"]);
            ProviderPassword = Convert.ToString(a["PrPassword"]);

            if (prd.ProviderName == Portal.*****.ToString())
            {
                ctreslt = ct.BeginInvoke(GIMonth, GIYear, ProviderUserName, ProviderPassword, null, null);

            }

            else if (prd.ProviderName == Portal.*****.ToString())
            {
                mmtreslt = mmt.BeginInvoke(GIMonth, GIYear, null, null);
            }
        }
        WaitHandle[] handleArray = { ctreslt.AsyncWaitHandle, mmtreslt.AsyncWaitHandle };
        WaitHandle.WaitAll(handleArray);
        Ctxml = ct.EndInvoke(ctreslt);
        Mmtxml = mmt.EndInvoke(mmtreslt);
        String Allxml = "<InventoryDetails>\n";
        string GIxml = "<InventoryDetails>\n" + Ctxml.InnerXml + " " + Mmtxml.InnerXml + "</InventoryDetails>";
        Allxml += "</InventoryDetails>";
        xml.LoadXml(GIxml);

        return xml;
    }

0 个答案:

没有答案