Hello all,
I have a web service that I am trying to retrieve data from
asynchronously. According to the MSDN documentation
(ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vbcon/html/vbtskCallingWebServiceAsynchronously.htm)
I should be able to call a webservice asynchronously using a delegate
function. The callback seems to work, but, when I assign the value to an
existing datagrid the program hangs. I don't quite understand, what do I
need to do?
TIA,
Jared
'Webservice call
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim cb As New AsyncCallback(AddressOf MyCallback)
myservice.BeginDoSomeAsyncStuff(cb, myservice)
End Sub
'Callback delegate
Private Sub MyCallback(ByVal ar As System.IAsyncResult)
Dim myservice As MCAD_Practice.MyService = ar.AsyncState
ds = myservice.EndDoSomeAsyncStuff(ar)
Me.DataGrid1.DataSource = ds.tables(0)
me.DataGrid1.Expand(True)
End Sub
'Web method - work just fine if I call it synchronously
<WebMethod()> _
Function DoSomeAsyncStuff() As DataSet
Dim conn As SqlConnection
Try
conn = New
SqlConnection("Server=localhost;database=northwind ;trusted_connection=true;")
conn.Open()
Dim da As New SqlDataAdapter("Select * from customers order by
CompanyName", conn)
Dim ds As New DataSet("NorthwindCustomers")
da.Fill(ds)
Return ds
Catch ex As Exception
Finally
conn.Close()
End Try
End Function