I have a number of commands that make calls to a soap web service (Betfair API). All are of the classic asynchronous programming model type ...
public void DoXXX( <input parameters ...> )
{
XXXRequest Request = new XXXRequest();
// populate Request from input parameters ...
BetfairService.BeginXXX( Request, XXXCallback, State );
}
private void XXXCallback(IAsyncResult Result)
{
XXXResponse Response = BetfairService.EndXXX(Result);
if (Response.ErrorCode == XXXErrorCode.OK)
// store data from Response
else
// deal with error
}
I want to execute a specified set of commands, and then do some calculations using the combined returned data values, once all of commands are completed.
I'm able to do this as a sequence, by making a queue of commands and having each callback method trigger the next command in the queue once it's complete, with the calculation as the last item in the queue. This is relatively slow however.
My ideal solution would be to have all of these commands running in parallel and then to have the calculation triggered once all of the commands are completed. I've tried looking at Task.Factory.FromAsync(), but all of the examples I can find only include direct calls to BeginXXX / EndXXX, not doing anything with the response.
Does anyone have any pointers for a suitable solution to this problem?