我想使用我的网络服务,但我似乎无法调用多个异步函数......除了从一个 AsyncCompleted 级联启动另一个?
导入picklists.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