Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i am new in threading concept i applied threading concept in my code when i run logic i have two beigninvoke concept when i executed it pass two beigninvoke then it will get output or else it executed only one beigninvoke means it will not get ouput it will get error in WaitHandle[] because of another thread will be pass in null how can i solve this problem

C#
[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;
}
Posted
Updated 5-Nov-15 20:33pm
v2
Comments
George Jonsson 6-Nov-15 2:34am    
It is not wrong to use a . or a , here and there.
Makes it easier to read.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900