Asyncronous call to web service

G

Guest

Hello All:

I have an executable that makes several asynchronous calls to a web service.
The executable increments a counter for each async Web service call and
decrements the counter whenever the call returns. When the counter == 0
(i.e. all calls have returned), I do some clean up and close down the
executable.

What if all of the calls don't return? What can I do if five async calls
are made and four come back. My current app would just sit around, waiting
for the fifth call to come back. Let's say that the network connection is
down; my app willl remain open and I don't want this. I'm not a big fan of
timers; they remind me of my VB 6 days.

Is there a more elegant way to handle this?

TIA,
 
G

Guest

Joe,
you would want to use some version of the WaitHandle, for example (untested):

void EnterBtn_Click(Object Src, EventArgs E)
{
MyMath.Math math = new MyMath.Math();
// Call to Add Web service method asynchronously
// and then wait for it to complete.
IAsyncResult result =
math.BeginAdd(Convert.ToInt32(Num1.Text),
Convert.ToInt32(Num2.Text),
null,
null);
// Wait for asynchronous call to complete or timeout
result.AsyncWaitHandle.WaitOne(timeout , true|false);
// Complete the asynchronous call to Add Web service method.
float total = math.EndAdd(result);
// Display results in a Label control.
Total.Text = "Total: " + total.ToString();
}


There are a number of overloads to the WaitOne method, you could even have
an array of WaitHandles.
Peter
 
G

Guest

Thanks.
--
Joe


Peter Bromberg said:
Joe,
you would want to use some version of the WaitHandle, for example (untested):

void EnterBtn_Click(Object Src, EventArgs E)
{
MyMath.Math math = new MyMath.Math();
// Call to Add Web service method asynchronously
// and then wait for it to complete.
IAsyncResult result =
math.BeginAdd(Convert.ToInt32(Num1.Text),
Convert.ToInt32(Num2.Text),
null,
null);
// Wait for asynchronous call to complete or timeout
result.AsyncWaitHandle.WaitOne(timeout , true|false);
// Complete the asynchronous call to Add Web service method.
float total = math.EndAdd(result);
// Display results in a Label control.
Total.Text = "Total: " + total.ToString();
}


There are a number of overloads to the WaitOne method, you could even have
an array of WaitHandles.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
 

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

Top