Unexpected Async Web Service behaviour

R

Ross Porter

I am calling a web service asyncronously and polling the
IAsync result variable to determine if processing is
complete(using IsCompleted),nif not completed, I am
writing a message to the console ("still processing...").
The problem seems to be that the IAsync result variable's
IsCompleted property never retruns true so the loop is
infinite.

Heres the code in vb: BTW -- the syncronous call is
working fine.

Sub Main()
Console.WriteLine("--------Begin Sync Call--------
----")
callsync()
Console.WriteLine("--------Begin Asyc Call--------
----")
callasync()
End Sub

Sub callsync()
Dim wR As New Web.WoodgroveOnlineBank
Dim aI As Web.Acct
aI = wR.GetAccount(1)
WriteValues(aI)
End Sub

Sub callasync()
Dim wR As New Web.WoodgroveOnlineBank
Dim cbObj As New AsyncCallback(AddressOf
CallBackMethod)
Dim IAR As IAsyncResult = wR.BeginGetAccount(1,
cbObj, wR)
Do Until IAR.IsCompleted
Console.WriteLine("Still processing . . .")
Thread.Sleep(1000)
Loop

End Sub

Sub CallBackMethod(ByVal ar As IAsyncResult)
Dim wR As Web.WoodgroveOnlineBank = ar.AsyncState
Dim act As Web.Acct
act = wR.EndGetAccount(ar)
WriteValues(act)
End Sub
Sub WriteValues(ByVal aI As Web.Acct)
Console.WriteLine("Account {0} - {2} has a
balance of {1}", _
aI.accountID, _
aI.balance, _
aI.description)
Console.Read()
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top