Hi,
yay - a much shorter post ^_^
I posted a question where my code was giving me a "cannot access disposed object". I get why that happened now:
I send of ~1000 request to the web service asynchronously.
I have a Complete delegate that increments a counter for each response.
Once the counter reaches the number of calls, it sets a WaitHandler.
The true issue was that I am getting thousands of responses for each request. where x max is ~1000, y goes off to 80k+ before the exception. The WaitHandle is already released but responses keep coming, hence the error occurs shortly after the method is out of scope.
Why am I getting so many responses?
I have removed the custom Async component of my web service and have just used the configuration of the service reference to generate Async methods.
here is my code:
private static void GenerateTests(int numberOfTests, Point itemsPerTest)
{
int y = 0;
ManualResetEvent resetEvent = new ManualResetEvent(false);
ServiceAccessClient client = new ServiceAccessClient();
for (int x = 0; x < numberOfTests; x++)
{
var details =
WriteLine("{0:D4}: Sending to secure access service", x);
#endregion
client.SendDetailsCompleted += delegate(object sender, SendDetailsCompletedEventArgs args)
{
y++;
if (args.Error != null)
{
WriteLine("ERROR: {0}", args.Error);
}
else
{
WriteLine("{2:D4}: response {0}: {1}", args.Result.ResponseCode, args.Result.ResponseDetail, y);
}
if (y == numberOfTests)
{
resetEvent.Set();
}
};
client.SendDetailsAsync(details, "x", Guid.Parse(NDA.TestGuid));
}
resetEvent.WaitOne();
}
Can anyone help? what am I doing wrong?
Many thanks
Andy