I create and start several threads, each thread executes the same method -
within the method, a web service is invoked. I find that the more threads I
use, the longer it takes for all of the threads to finish. The threads are
asynchronous, correct? And I thought each would be able to use it's own
version of the web service. Am I wrong, does the web service force only one
thread at a time to execute?
Here is code if interested... I'm using NUnit for it.
static Int32 _threadFinished = 0;
[Test]
public void SimulateManyUsers()
{
Int32 howManyUsers = 10;
for (Int32 x = 0; x < howManyUsers; x++)
{
Thread t = new Thread(new ThreadStart(this.UseService));
t.Start();
}
//Give threads a chance to finish
Thread.Sleep(20000);
//Check the results
Assertion.AssertEquals("One or more of the threads did not
finish.",howManyUsers,_threadFinished);
}
private void UseService()
{
DateTime refDate = new DateTime(1998,07,04);
DateTime respDate = new DateTime(2003,06,28);
ArmCalcParameters[] i = new ArmCalcParameters[25];
for (Int32 x = 0; x< i.Length; x++)
{
i[x] = new ArmCalcParameters();
i[x].SR = "16";
i[x].SRMP = 12.32f;
i[x].ReferenceDate = refDate;
i[x].ResponseDate = respDate;
i[x].CalcType = CalculationType.SRMPtoARM;
i[x].TransId = x.ToString();
}
ArmCalcParametersOut[] o = new ArmCalcParametersOut[i.Length];
ArmCalcService svc = new ArmCalcService();
o = svc.CalculateBatch(i);
_threadFinished++;
}