Business Connector and Multithreading over the same object.

Hi

I want to know something.

Im able to perform several connections on AX2009 using a Parallel.For from C# using the same credentials, that is ok, the connections are done and no error are throw.

But.

when i call some AX class using business connector on this the Parallel loop, the server throws messag like “The server terminated the session.” What Im doing whrong? If Im able to have several connections, why Im not able to execute the method ?

  Parallel.For(0, 2, (i, state) =>
            {
              // here the logon 
            NetworkCredential nc = new System.Net.NetworkCredential("user", "passwd", "Domain");  
            this.axp.LogonAs("user", "", nc, "", "", "", "");     
            // all logons are ok no error raise.
            
            // here is the issue happens
             vara result  = axp.CallStaticClassMethod("Myclass", "MystaticMethodName", parameter);
            // for only one execution the result is fine and ok. But for more than one i get messages like 
            // "The server terminated the session." 
            
            }

can you please share your MystaticMethodName structure also try to use the below to detect actual error
try
{

axp.LogonAs(user, “domain”, nc, “DataArea”, null, null, null);
string result;
Parallel.For(0, 2, (i, state) =>

{
{
result = (string)axp.CallStaticClassMethod(“MyClass”, “MystaticMethodName”, para);
infoMessage = “”; // this to be declared on your web method parameters
}
catch (Exception ea)
{
hasError = true; // this to be declared on your web method parameters
infoMessage = ea.Message; // this to be declared on your web method parameters
}
}

Hi Samer.
Thanks for the help. But actually the code in the way I put here works . I realize that my problem was were I create the connection. On my application the Axapta object was been created outside the thread… Looking the code here after I fix my problem moving the creation of the Axapta to inside the parallel.for and it work beautifully . Thanks anyway.