Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET chained asynchronous calls
    text
    copied!<p>I have an ASP.NET page that needs to make calls to multiple web services to return data. I'd like to run these requests in parallel, and using the PageAsyncTask class appears to be the most appropriate way to do that. The trick is that there are five calls--say A, B, C, D, and E. Calls A &amp; B must be made sequentially, as must C &amp; D. The AB pair, the CD pair, and E can all run in parallel.</p> <p>It doesn't appear that I can use the "executeInParallel" parameter of the PageAsyncTask constructor to create 5 tasks and get this configuration of parallel/sequential.</p> <p>I've tried creating 3 tasks, two of which have chained asynchronous calls (similar to <a href="http://msdn.microsoft.com/en-us/library/dwba7yy7(VS.80).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/dwba7yy7(VS.80).aspx</a>). When I try to do that in the context of a PageAsyncTask, I get an error indicating that the end function can only be called once. I've tried wrapping the chained set of 3 functions in a pair of functions that the PageAsyncTask uses, and that results in the end function never being called (thus a timeout).</p> <p>Is there a good way to do this?</p> <p>Edit: If it's useful, here's a simplified version of the code I'm attempting and getting the error that the end function can only be called once.</p> <pre><code> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim objMB As New BusObject.AsyncTasks(AddressOf dummy) Dim objTask As New PageAsyncTask(AddressOf objMB.BeginStartSession, AddressOf objMB.EndGetList, Nothing, Nothing, True) RegisterAsyncTask(objTask) Dim i As Integer = 0 End Sub Public Class BusObject Public Class AsyncState Public SecondCallback As AsyncCallback End Class Public Class AsyncTasks Dim fn_Callback As PageCallback Public Delegate Sub PageCallback(ByVal objData As Object) Public Sub New(ByVal fnCallback As PageCallback) fn_Callback = fnCallback End Sub Public Function BeginStartSession(ByVal sender As Object, ByVal e As EventArgs, ByVal cb As AsyncCallback, ByVal extraData As Object) As IAsyncResult Dim objWS As New com.WebService Dim objX As New AsyncState objX.SecondCallback = cb Return objWS.BeginWSFunction1("param1", "param2", AddressOf EndStartSession, objX) End Function Public Sub EndStartSession(ByVal objAsyncResult As IAsyncResult) Dim objWS As New com.WebService Dim strSessionKey As String = objWS.EndWSFunction1(objAsyncResult) Dim objState As AsyncState = objAsyncResult.AsyncState objWS.BeginWSFunction2("p1", "p2", "p3", "p4", "p5", strSessionKey, True, objState.SecondCallback, objState) End Sub Public Sub EndGetList(ByVal objState As IAsyncResult) Dim objWS As New com.WebService Dim objResult As com.WebService.Result = objWS.EndWSFunction2(objState) Dim lstReturn As New List(Of BusObject) fn_Callback(lstReturn) End Sub End Class End Class </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload