0

Webサービスを使用したいのですが、複数の非同期関数を呼び出せないようです...1つのAsyncCompletedからカスケードして別のAsyncCompletedを開始する以外は??

選択リストをインポートします。MyWebService

パブリッククラスメイン

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

内部例外: {"非同期処理中にエラーが発生しました。複数の非同期同時操作を実行するには、一意の状態オブジェクトが必要です。"}

編集/解決策

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
4

1 に答える 1

2

これは、この問題の良いc#の例を含むいくつかの記事です。一意の状態オブジェクトを非同期メソッドに渡す必要があると記載されています。

ws.GetCustomersAsDatatableAsync(System.Guid.NewGuid())
ws.GetRoutesAsDatatableAsync(System.Guid.NewGuid())
于 2013-03-27T12:29:55.417 に答える