0

I would like to use my webservice but I can't seem to call multiple async functions... Other than cascading from one AsyncCompleted to start another??

Imports picklists.MyWebService

Public Class main

Dim WithEvents ws As New picklists.MyWebService.picklists

Private Sub main_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    ws.GetCustomersAsDatatableAsync()
    ws.GetRoutesAsDatatableAsync()

End Sub

Private Sub ws_GetCustomersAsDatatableCompleted(sender As Object, e As GetCustomersAsDatatableCompletedEventArgs) Handles ws.GetCustomersAsDatatableCompleted

    Dim dt As DataTable = CType(e.Result, DataTable)

    cmb_customer.DataSource = dt
    cmb_customer.DisplayMember = "NAME"

End Sub

Private Sub ws_GetRoutesAsDatatableCompleted(sender As Object, e As GetRoutesAsDatatableCompletedEventArgs) Handles ws.GetRoutesAsDatatableCompleted

    Dim dt As DataTable = CType(e.Result, DataTable)

    cmb_route.DataSource = dt
    cmb_route.DisplayMember = "NAME"

End Sub

Innerexception: {"There was an error during asynchronous processing. Unique state object is required for multiple asynchronous simultaneous operations to be outstanding."}

EDIT/SOLUTION:

Imports picklists.MyWebService

Public Class main

    Dim WithEvents ws As New picklists.MyWebService.picklists

    Private Sub main_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        ws.GetCustomersAsDatatableAsync(Guid.NewGuid.ToString)
        ws.GetRoutesAsDatatableAsync(Guid.NewGuid.ToString)

    End Sub

    Private Sub ws_GetCustomersAsDatatableCompleted(sender As Object, e As GetCustomersAsDatatableCompletedEventArgs) Handles ws.GetCustomersAsDatatableCompleted

        Dim g As String = e.UserState

        Dim dt As DataTable = CType(e.Result, DataTable)

        cmb_customer.DataSource = dt
        cmb_customer.DisplayMember = "NAME"

    End Sub

    Private Sub ws_GetRoutesAsDatatableCompleted(sender As Object, e As GetRoutesAsDatatableCompletedEventArgs) Handles ws.GetRoutesAsDatatableCompleted

        Dim g As String = e.UserState

        Dim dt As DataTable = CType(e.Result, DataTable)

        cmb_route.DataSource = dt
        cmb_route.DisplayMember = "NAME"

    End Sub
1
  • 1
    What have you done so far? Show us your code. What exactly can't you implement? Commented Mar 27, 2013 at 11:03

1 Answer 1

2

Here is some article with good c# example of this problem. It states, that you should pass a unique state object to async method.

ws.GetCustomersAsDatatableAsync(System.Guid.NewGuid())
ws.GetRoutesAsDatatableAsync(System.Guid.NewGuid())
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Dmitry, but I don't fully understand how to implement that answer in my solution. The function calls require no parameter, how should I pass a GUID/State object?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.