473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

AsyncCallback question

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
Nov 21 '05 #1
2 2116
Hi,

A couple of msdn tv episodes about it.

http://msdn.microsoft.com/msdntv/epi...B/manifest.xml

http://msdn.microsoft.com/msdntv/epi...B/manifest.xml

Ken
---------------------
"Jared" <VB***********@email.com> wrote in message
news:10*************@corp.supernews.com...
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

Nov 21 '05 #2
Ken,
That was the kicker, I completely overlooked the fact that the web
service was being called from a seperate thread. Thanks,
Jared

Here is my working example if anyone else was following this thread.

Delegate Sub UpdateDataGrid(ByVal ds As DataSet)

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

Private Sub MyCallback(ByVal ar As System.IAsyncResult)
Dim myservice As MyWebService.MyService = ar.AsyncState
Dim data As DataSet = myservice.EndDoSomeAsyncStuff(ar)
'Delegate
Dim grid As New UpdateDataGrid(AddressOf Bind)
Me.Invoke(grid, New Object() {Data})
End Sub

Private Sub Bind(ByVal ds As DataSet)
Me.DataGrid1.DataSource = ds.Tables(0)
Me.DataGrid1.Expand(True)
End Sub

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

A couple of msdn tv episodes about it.

http://msdn.microsoft.com/msdntv/epi...B/manifest.xml

http://msdn.microsoft.com/msdntv/epi...B/manifest.xml

Ken
---------------------
"Jared" <VB***********@email.com> wrote in message
news:10*************@corp.supernews.com...
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

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jim P. | last post by:
I'm having trouble returning an object from an AsyncCallback called inside a threaded infinite loop. I'm working on a Peer2Peer app that uses an AsyncCallback to rerieve the data from the remote...
11
by: Doug Thews | last post by:
I've been working on some samples that use BeginInvoke/EndInvoke. In one example, I call BeginInvoke and pass it an AsyncCallback function pointer. I was messing around with ReaderWriterLocks and...
1
by: Alper AKCAYOZ | last post by:
Hello, I have developped asynchronous socket communication with blocking Socket commands (accept, connect, send, receive) by using threads on Windows .NET Forms. It is working properly. Now I...
2
by: Morgan Cheng | last post by:
In asynchronous model, BeginXXX method returns a IAsnycResult-derived object. IAsyncResult.AsyncWaitHandle will be signaled when the asynchronous job is complete; and BeginXXX method has a argument...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.