By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,919 Members | 1,587 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,919 IT Pros & Developers. It's quick & easy.

Waiting for async webservices to finish.

P: n/a


I am looping through a text file, and with each row, I launch a web service,
asynchronously.

Before I move on to the next step in the process, I want to make sure that
all the web services have completed.

How can I do this?

If I were to just put a Thread.Sleep with some arbitrary number ( say 5
minutes ) would the asynch web services continue to process? Or would they
be frozen while the main thread sleeps?


--
Texeme Textcasting Technology
http://www.texeme.com
Nov 23 '05 #1
Share this Question
Share on Google+
30 Replies


P: n/a
when u got the IAsyncResult
call this :

ar.AsyncWaitHandle.WaitOne();
(assume u IAsncResult instance is ar)

it will wait the asnyc call to complete

optioanly , u can call
ar.IsCompleted() to decide
--
Can You?You Can.
"ja*****@texeme.com" wrote:


I am looping through a text file, and with each row, I launch a web service,
asynchronously.

Before I move on to the next step in the process, I want to make sure that
all the web services have completed.

How can I do this?

If I were to just put a Thread.Sleep with some arbitrary number ( say 5
minutes ) would the asynch web services continue to process? Or would they
be frozen while the main thread sleeps?


--
Texeme Textcasting Technology
http://www.texeme.com

Nov 23 '05 #2

P: n/a
when u got the IAsyncResult
call this :

ar.AsyncWaitHandle.WaitOne();
(assume u IAsncResult instance is ar)

it will wait the asnyc call to complete

optioanly , u can call
ar.IsCompleted() to decide
--
Can You?You Can.
"ja*****@texeme.com" wrote:


I am looping through a text file, and with each row, I launch a web service,
asynchronously.

Before I move on to the next step in the process, I want to make sure that
all the web services have completed.

How can I do this?

If I were to just put a Thread.Sleep with some arbitrary number ( say 5
minutes ) would the asynch web services continue to process? Or would they
be frozen while the main thread sleeps?


--
Texeme Textcasting Technology
http://www.texeme.com

Nov 23 '05 #3

P: n/a
when u got the IAsyncResult
call this :

ar.AsyncWaitHandle.WaitOne();
(assume u IAsncResult instance is ar)

it will wait the asnyc call to complete

optioanly , u can call
ar.IsCompleted() to decide
--
Can You?You Can.
"ja*****@texeme.com" wrote:


I am looping through a text file, and with each row, I launch a web service,
asynchronously.

Before I move on to the next step in the process, I want to make sure that
all the web services have completed.

How can I do this?

If I were to just put a Thread.Sleep with some arbitrary number ( say 5
minutes ) would the asynch web services continue to process? Or would they
be frozen while the main thread sleeps?


--
Texeme Textcasting Technology
http://www.texeme.com

Nov 23 '05 #4

P: n/a
when u got the IAsyncResult
call this :

ar.AsyncWaitHandle.WaitOne();
(assume u IAsncResult instance is ar)

it will wait the asnyc call to complete

optioanly , u can call
ar.IsCompleted() to decide
--
Can You?You Can.
"ja*****@texeme.com" wrote:


I am looping through a text file, and with each row, I launch a web service,
asynchronously.

Before I move on to the next step in the process, I want to make sure that
all the web services have completed.

How can I do this?

If I were to just put a Thread.Sleep with some arbitrary number ( say 5
minutes ) would the asynch web services continue to process? Or would they
be frozen while the main thread sleeps?


--
Texeme Textcasting Technology
http://www.texeme.com

Nov 23 '05 #5

P: n/a


Ok, after trying a bunch of things, I found that I was being thrown off
by calling the web service locally from my XP machine via studio.

Somehow, it didn't have the power to keep up with some many asynchronous
requests. I then configured the web service to be dynamic in my
client so I could point it to a production deployment running on a w2k
server.

After that I used a mix of the methods suggested here.

I used an ArrayList ( great idea, because since I'm reading a file line
by line, I dont' know in advance how many calls I'm making ).

I can't use the WaitHandles because it's limited to 64.

So, I put the IAsyncResult into the array list and then call the
IsCompleted() method in a while loop on each element.

BillyLiu007 wrote:
when u got the IAsyncResult
call this :

ar.AsyncWaitHandle.WaitOne();
(assume u IAsncResult instance is ar)

it will wait the asnyc call to complete

optioanly , u can call
ar.IsCompleted() to decide

Nov 23 '05 #6

P: n/a


Ok, after trying a bunch of things, I found that I was being thrown off
by calling the web service locally from my XP machine via studio.

Somehow, it didn't have the power to keep up with some many asynchronous
requests. I then configured the web service to be dynamic in my
client so I could point it to a production deployment running on a w2k
server.

After that I used a mix of the methods suggested here.

I used an ArrayList ( great idea, because since I'm reading a file line
by line, I dont' know in advance how many calls I'm making ).

I can't use the WaitHandles because it's limited to 64.

So, I put the IAsyncResult into the array list and then call the
IsCompleted() method in a while loop on each element.

BillyLiu007 wrote:
when u got the IAsyncResult
call this :

ar.AsyncWaitHandle.WaitOne();
(assume u IAsncResult instance is ar)

it will wait the asnyc call to complete

optioanly , u can call
ar.IsCompleted() to decide

Nov 23 '05 #7

P: n/a
Hi,

I'd keep an array of the async delegates themselves and call EndInvoke on
each of the delegates in a loop. Thus, you won't be wasting CPU cycles on
polling the array of IAsyncResult references in a loop.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
<ja*****@texeme.com> wrote in message news:42**************@texeme.com...


Ok, after trying a bunch of things, I found that I was being thrown off by
calling the web service locally from my XP machine via studio.

Somehow, it didn't have the power to keep up with some many asynchronous
requests. I then configured the web service to be dynamic in my client
so I could point it to a production deployment running on a w2k server.

After that I used a mix of the methods suggested here.

I used an ArrayList ( great idea, because since I'm reading a file line by
line, I dont' know in advance how many calls I'm making ).

I can't use the WaitHandles because it's limited to 64.

So, I put the IAsyncResult into the array list and then call the
IsCompleted() method in a while loop on each element.

BillyLiu007 wrote:
when u got the IAsyncResult
call this :

ar.AsyncWaitHandle.WaitOne();
(assume u IAsncResult instance is ar)

it will wait the asnyc call to complete optioanly , u can call
ar.IsCompleted() to decide


Nov 23 '05 #8

P: n/a
Hi,

I'd keep an array of the async delegates themselves and call EndInvoke on
each of the delegates in a loop. Thus, you won't be wasting CPU cycles on
polling the array of IAsyncResult references in a loop.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
<ja*****@texeme.com> wrote in message news:42**************@texeme.com...


Ok, after trying a bunch of things, I found that I was being thrown off by
calling the web service locally from my XP machine via studio.

Somehow, it didn't have the power to keep up with some many asynchronous
requests. I then configured the web service to be dynamic in my client
so I could point it to a production deployment running on a w2k server.

After that I used a mix of the methods suggested here.

I used an ArrayList ( great idea, because since I'm reading a file line by
line, I dont' know in advance how many calls I'm making ).

I can't use the WaitHandles because it's limited to 64.

So, I put the IAsyncResult into the array list and then call the
IsCompleted() method in a while loop on each element.

BillyLiu007 wrote:
when u got the IAsyncResult
call this :

ar.AsyncWaitHandle.WaitOne();
(assume u IAsncResult instance is ar)

it will wait the asnyc call to complete optioanly , u can call
ar.IsCompleted() to decide


Nov 23 '05 #9

P: n/a
jabailo,
| So, I put the IAsyncResult into the array list and then call the
| IsCompleted() method in a while loop on each element.
As Dmytro suggests: This is a "bad" idea as you are burning CPU cycles
polling IsCompleted, calling EndSomeMethod causes your loop to wait on a
WaitHandle under the covers, which is much friendlier.

The sample I gave should work with minimal effort.

Hope this helps
Jay

<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
|
|
| Ok, after trying a bunch of things, I found that I was being thrown off
| by calling the web service locally from my XP machine via studio.
|
| Somehow, it didn't have the power to keep up with some many asynchronous
| requests. I then configured the web service to be dynamic in my
| client so I could point it to a production deployment running on a w2k
| server.
|
| After that I used a mix of the methods suggested here.
|
| I used an ArrayList ( great idea, because since I'm reading a file line
| by line, I dont' know in advance how many calls I'm making ).
|
| I can't use the WaitHandles because it's limited to 64.
|
| So, I put the IAsyncResult into the array list and then call the
| IsCompleted() method in a while loop on each element.
|
| BillyLiu007 wrote:
| > when u got the IAsyncResult
| > call this :
| >
| > ar.AsyncWaitHandle.WaitOne();
| > (assume u IAsncResult instance is ar)
| >
| > it will wait the asnyc call to complete
| >
| > optioanly , u can call
| > ar.IsCompleted() to decide
Nov 23 '05 #10

P: n/a
jabailo,
| So, I put the IAsyncResult into the array list and then call the
| IsCompleted() method in a while loop on each element.
As Dmytro suggests: This is a "bad" idea as you are burning CPU cycles
polling IsCompleted, calling EndSomeMethod causes your loop to wait on a
WaitHandle under the covers, which is much friendlier.

The sample I gave should work with minimal effort.

Hope this helps
Jay

<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
|
|
| Ok, after trying a bunch of things, I found that I was being thrown off
| by calling the web service locally from my XP machine via studio.
|
| Somehow, it didn't have the power to keep up with some many asynchronous
| requests. I then configured the web service to be dynamic in my
| client so I could point it to a production deployment running on a w2k
| server.
|
| After that I used a mix of the methods suggested here.
|
| I used an ArrayList ( great idea, because since I'm reading a file line
| by line, I dont' know in advance how many calls I'm making ).
|
| I can't use the WaitHandles because it's limited to 64.
|
| So, I put the IAsyncResult into the array list and then call the
| IsCompleted() method in a while loop on each element.
|
| BillyLiu007 wrote:
| > when u got the IAsyncResult
| > call this :
| >
| > ar.AsyncWaitHandle.WaitOne();
| > (assume u IAsncResult instance is ar)
| >
| > it will wait the asnyc call to complete
| >
| > optioanly , u can call
| > ar.IsCompleted() to decide
Nov 23 '05 #11

P: n/a

Ok.

I think when I implemented that method I was still using the local web
server ( which was causing grief ).

Now that I know it was the source of our problems, I will switch back to
the method you suggest!
Jay B. Harlow [MVP - Outlook] wrote:
jabailo,
| So, I put the IAsyncResult into the array list and then call the
| IsCompleted() method in a while loop on each element.
As Dmytro suggests: This is a "bad" idea as you are burning CPU cycles
polling IsCompleted, calling EndSomeMethod causes your loop to wait on a
WaitHandle under the covers, which is much friendlier.

The sample I gave should work with minimal effort.

Hope this helps
Jay

<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
|
|
| Ok, after trying a bunch of things, I found that I was being thrown off
| by calling the web service locally from my XP machine via studio.
|
| Somehow, it didn't have the power to keep up with some many asynchronous
| requests. I then configured the web service to be dynamic in my
| client so I could point it to a production deployment running on a w2k
| server.
|
| After that I used a mix of the methods suggested here.
|
| I used an ArrayList ( great idea, because since I'm reading a file line
| by line, I dont' know in advance how many calls I'm making ).
|
| I can't use the WaitHandles because it's limited to 64.
|
| So, I put the IAsyncResult into the array list and then call the
| IsCompleted() method in a while loop on each element.
|
| BillyLiu007 wrote:
| > when u got the IAsyncResult
| > call this :
| >
| > ar.AsyncWaitHandle.WaitOne();
| > (assume u IAsncResult instance is ar)
| >
| > it will wait the asnyc call to complete
| >
| > optioanly , u can call
| > ar.IsCompleted() to decide

Nov 23 '05 #12

P: n/a

Ok.

I think when I implemented that method I was still using the local web
server ( which was causing grief ).

Now that I know it was the source of our problems, I will switch back to
the method you suggest!
Jay B. Harlow [MVP - Outlook] wrote:
jabailo,
| So, I put the IAsyncResult into the array list and then call the
| IsCompleted() method in a while loop on each element.
As Dmytro suggests: This is a "bad" idea as you are burning CPU cycles
polling IsCompleted, calling EndSomeMethod causes your loop to wait on a
WaitHandle under the covers, which is much friendlier.

The sample I gave should work with minimal effort.

Hope this helps
Jay

<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
|
|
| Ok, after trying a bunch of things, I found that I was being thrown off
| by calling the web service locally from my XP machine via studio.
|
| Somehow, it didn't have the power to keep up with some many asynchronous
| requests. I then configured the web service to be dynamic in my
| client so I could point it to a production deployment running on a w2k
| server.
|
| After that I used a mix of the methods suggested here.
|
| I used an ArrayList ( great idea, because since I'm reading a file line
| by line, I dont' know in advance how many calls I'm making ).
|
| I can't use the WaitHandles because it's limited to 64.
|
| So, I put the IAsyncResult into the array list and then call the
| IsCompleted() method in a while loop on each element.
|
| BillyLiu007 wrote:
| > when u got the IAsyncResult
| > call this :
| >
| > ar.AsyncWaitHandle.WaitOne();
| > (assume u IAsncResult instance is ar)
| >
| > it will wait the asnyc call to complete
| >
| > optioanly , u can call
| > ar.IsCompleted() to decide

Nov 23 '05 #13

P: n/a

Oh, actually, what I do is this:

foreach(IAsyncResult ar in results)
ar.AsyncWaitHandle.WaitOne();

So presumably it doesn't entail the spining CPU - but just raises an
event and waits until complete.


Jay B. Harlow [MVP - Outlook] wrote:
jabailo,
| So, I put the IAsyncResult into the array list and then call the
| IsCompleted() method in a while loop on each element.
As Dmytro suggests: This is a "bad" idea as you are burning CPU cycles
polling IsCompleted, calling EndSomeMethod causes your loop to wait on a
WaitHandle under the covers, which is much friendlier.

The sample I gave should work with minimal effort.

Hope this helps
Jay

<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
|
|
| Ok, after trying a bunch of things, I found that I was being thrown off
| by calling the web service locally from my XP machine via studio.
|
| Somehow, it didn't have the power to keep up with some many asynchronous
| requests. I then configured the web service to be dynamic in my
| client so I could point it to a production deployment running on a w2k
| server.
|
| After that I used a mix of the methods suggested here.
|
| I used an ArrayList ( great idea, because since I'm reading a file line
| by line, I dont' know in advance how many calls I'm making ).
|
| I can't use the WaitHandles because it's limited to 64.
|
| So, I put the IAsyncResult into the array list and then call the
| IsCompleted() method in a while loop on each element.
|
| BillyLiu007 wrote:
| > when u got the IAsyncResult
| > call this :
| >
| > ar.AsyncWaitHandle.WaitOne();
| > (assume u IAsncResult instance is ar)
| >
| > it will wait the asnyc call to complete
| >
| > optioanly , u can call
| > ar.IsCompleted() to decide

Nov 23 '05 #14

P: n/a

Oh, actually, what I do is this:

foreach(IAsyncResult ar in results)
ar.AsyncWaitHandle.WaitOne();

So presumably it doesn't entail the spining CPU - but just raises an
event and waits until complete.


Jay B. Harlow [MVP - Outlook] wrote:
jabailo,
| So, I put the IAsyncResult into the array list and then call the
| IsCompleted() method in a while loop on each element.
As Dmytro suggests: This is a "bad" idea as you are burning CPU cycles
polling IsCompleted, calling EndSomeMethod causes your loop to wait on a
WaitHandle under the covers, which is much friendlier.

The sample I gave should work with minimal effort.

Hope this helps
Jay

<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
|
|
| Ok, after trying a bunch of things, I found that I was being thrown off
| by calling the web service locally from my XP machine via studio.
|
| Somehow, it didn't have the power to keep up with some many asynchronous
| requests. I then configured the web service to be dynamic in my
| client so I could point it to a production deployment running on a w2k
| server.
|
| After that I used a mix of the methods suggested here.
|
| I used an ArrayList ( great idea, because since I'm reading a file line
| by line, I dont' know in advance how many calls I'm making ).
|
| I can't use the WaitHandles because it's limited to 64.
|
| So, I put the IAsyncResult into the array list and then call the
| IsCompleted() method in a while loop on each element.
|
| BillyLiu007 wrote:
| > when u got the IAsyncResult
| > call this :
| >
| > ar.AsyncWaitHandle.WaitOne();
| > (assume u IAsncResult instance is ar)
| >
| > it will wait the asnyc call to complete
| >
| > optioanly , u can call
| > ar.IsCompleted() to decide

Nov 23 '05 #15

P: n/a
jabailo,
Although its non-conventional, that should not cause any spinning...

I would still favor EndSomeMethod over ar.AsyncWaitHandle.WaitOne.

My understanding is that the EndSomeMethod call will clean up any resources
that may have been used (such as the WaitHandle itself). Plus it ensures any
return value or Exception is returned to your process. I understand that the
EndSomeMethod should be called even when using the callback as you
originally were. Unfortunately I don't have links to where I got this
impression...

Hope this helps
Jay

<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
|
| Oh, actually, what I do is this:
|
| foreach(IAsyncResult ar in results)
| ar.AsyncWaitHandle.WaitOne();
|
| So presumably it doesn't entail the spining CPU - but just raises an
| event and waits until complete.
|
|
|
|
| Jay B. Harlow [MVP - Outlook] wrote:
| > jabailo,
| > | So, I put the IAsyncResult into the array list and then call the
| > | IsCompleted() method in a while loop on each element.
| > As Dmytro suggests: This is a "bad" idea as you are burning CPU cycles
| > polling IsCompleted, calling EndSomeMethod causes your loop to wait on a
| > WaitHandle under the covers, which is much friendlier.
| >
| > The sample I gave should work with minimal effort.
| >
| > Hope this helps
| > Jay
| >
| > <ja*****@texeme.com> wrote in message
news:42**************@texeme.com...
| > |
| > |
| > | Ok, after trying a bunch of things, I found that I was being thrown
off
| > | by calling the web service locally from my XP machine via studio.
| > |
| > | Somehow, it didn't have the power to keep up with some many
asynchronous
| > | requests. I then configured the web service to be dynamic in my
| > | client so I could point it to a production deployment running on a w2k
| > | server.
| > |
| > | After that I used a mix of the methods suggested here.
| > |
| > | I used an ArrayList ( great idea, because since I'm reading a file
line
| > | by line, I dont' know in advance how many calls I'm making ).
| > |
| > | I can't use the WaitHandles because it's limited to 64.
| > |
| > | So, I put the IAsyncResult into the array list and then call the
| > | IsCompleted() method in a while loop on each element.
| > |
| > | BillyLiu007 wrote:
| > | > when u got the IAsyncResult
| > | > call this :
| > | >
| > | > ar.AsyncWaitHandle.WaitOne();
| > | > (assume u IAsncResult instance is ar)
| > | >
| > | > it will wait the asnyc call to complete
| > | >
| > | > optioanly , u can call
| > | > ar.IsCompleted() to decide
| >
| >
Nov 23 '05 #16

P: n/a
jabailo,
Although its non-conventional, that should not cause any spinning...

I would still favor EndSomeMethod over ar.AsyncWaitHandle.WaitOne.

My understanding is that the EndSomeMethod call will clean up any resources
that may have been used (such as the WaitHandle itself). Plus it ensures any
return value or Exception is returned to your process. I understand that the
EndSomeMethod should be called even when using the callback as you
originally were. Unfortunately I don't have links to where I got this
impression...

Hope this helps
Jay

<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
|
| Oh, actually, what I do is this:
|
| foreach(IAsyncResult ar in results)
| ar.AsyncWaitHandle.WaitOne();
|
| So presumably it doesn't entail the spining CPU - but just raises an
| event and waits until complete.
|
|
|
|
| Jay B. Harlow [MVP - Outlook] wrote:
| > jabailo,
| > | So, I put the IAsyncResult into the array list and then call the
| > | IsCompleted() method in a while loop on each element.
| > As Dmytro suggests: This is a "bad" idea as you are burning CPU cycles
| > polling IsCompleted, calling EndSomeMethod causes your loop to wait on a
| > WaitHandle under the covers, which is much friendlier.
| >
| > The sample I gave should work with minimal effort.
| >
| > Hope this helps
| > Jay
| >
| > <ja*****@texeme.com> wrote in message
news:42**************@texeme.com...
| > |
| > |
| > | Ok, after trying a bunch of things, I found that I was being thrown
off
| > | by calling the web service locally from my XP machine via studio.
| > |
| > | Somehow, it didn't have the power to keep up with some many
asynchronous
| > | requests. I then configured the web service to be dynamic in my
| > | client so I could point it to a production deployment running on a w2k
| > | server.
| > |
| > | After that I used a mix of the methods suggested here.
| > |
| > | I used an ArrayList ( great idea, because since I'm reading a file
line
| > | by line, I dont' know in advance how many calls I'm making ).
| > |
| > | I can't use the WaitHandles because it's limited to 64.
| > |
| > | So, I put the IAsyncResult into the array list and then call the
| > | IsCompleted() method in a while loop on each element.
| > |
| > | BillyLiu007 wrote:
| > | > when u got the IAsyncResult
| > | > call this :
| > | >
| > | > ar.AsyncWaitHandle.WaitOne();
| > | > (assume u IAsncResult instance is ar)
| > | >
| > | > it will wait the asnyc call to complete
| > | >
| > | > optioanly , u can call
| > | > ar.IsCompleted() to decide
| >
| >
Nov 23 '05 #17

P: n/a
Actually, I am using both.

I keep the EndInvoke that runs on each thread...so it cleans up the
thread, on the thread, when it finishes. But the WaitOne lets me use
the handles, on the System.Thread to determine when each async thread is
finished.

So my code looks like:

while((s=sr.ReadLine())!=null)
results.Add(this.as400maketable(s,tableString));

foreach(IAsyncResult ar in results)
ar.AsyncWaitHandle.WaitOne();

private IAsyncResult as400maketable(string line, string tablename)
{
AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
IAsyncResult ar = as400.BegininsertPolarData(
line, tablename, delCB, null);
return ar;
}

void AsyncCB(IAsyncResult ar)
{
as400.EndinsertPolarData(ar);
}
;


Jay B. Harlow [MVP - Outlook] wrote:
jabailo,
Although its non-conventional, that should not cause any spinning...

I would still favor EndSomeMethod over ar.AsyncWaitHandle.WaitOne.

My understanding is that the EndSomeMethod call will clean up any resources
that may have been used (such as the WaitHandle itself). Plus it ensures any
return value or Exception is returned to your process. I understand that the
EndSomeMethod should be called even when using the callback as you
originally were. Unfortunately I don't have links to where I got this
impression...

Hope this helps
Jay

<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
|
| Oh, actually, what I do is this:
|
| foreach(IAsyncResult ar in results)
| ar.AsyncWaitHandle.WaitOne();
|
| So presumably it doesn't entail the spining CPU - but just raises an
| event and waits until complete.
|
|
|
|
| Jay B. Harlow [MVP - Outlook] wrote:
| > jabailo,
| > | So, I put the IAsyncResult into the array list and then call the
| > | IsCompleted() method in a while loop on each element.
| > As Dmytro suggests: This is a "bad" idea as you are burning CPU cycles
| > polling IsCompleted, calling EndSomeMethod causes your loop to wait on a
| > WaitHandle under the covers, which is much friendlier.
| >
| > The sample I gave should work with minimal effort.
| >
| > Hope this helps
| > Jay
| >
| > <ja*****@texeme.com> wrote in message
news:42**************@texeme.com...
| > |
| > |
| > | Ok, after trying a bunch of things, I found that I was being thrown
off
| > | by calling the web service locally from my XP machine via studio.
| > |
| > | Somehow, it didn't have the power to keep up with some many
asynchronous
| > | requests. I then configured the web service to be dynamic in my
| > | client so I could point it to a production deployment running on a w2k
| > | server.
| > |
| > | After that I used a mix of the methods suggested here.
| > |
| > | I used an ArrayList ( great idea, because since I'm reading a file
line
| > | by line, I dont' know in advance how many calls I'm making ).
| > |
| > | I can't use the WaitHandles because it's limited to 64.
| > |
| > | So, I put the IAsyncResult into the array list and then call the
| > | IsCompleted() method in a while loop on each element.
| > |
| > | BillyLiu007 wrote:
| > | > when u got the IAsyncResult
| > | > call this :
| > | >
| > | > ar.AsyncWaitHandle.WaitOne();
| > | > (assume u IAsncResult instance is ar)
| > | >
| > | > it will wait the asnyc call to complete
| > | >
| > | > optioanly , u can call
| > | > ar.IsCompleted() to decide
| >
| >

Nov 23 '05 #18

P: n/a
Actually, I am using both.

I keep the EndInvoke that runs on each thread...so it cleans up the
thread, on the thread, when it finishes. But the WaitOne lets me use
the handles, on the System.Thread to determine when each async thread is
finished.

So my code looks like:

while((s=sr.ReadLine())!=null)
results.Add(this.as400maketable(s,tableString));

foreach(IAsyncResult ar in results)
ar.AsyncWaitHandle.WaitOne();

private IAsyncResult as400maketable(string line, string tablename)
{
AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
IAsyncResult ar = as400.BegininsertPolarData(
line, tablename, delCB, null);
return ar;
}

void AsyncCB(IAsyncResult ar)
{
as400.EndinsertPolarData(ar);
}
;


Jay B. Harlow [MVP - Outlook] wrote:
jabailo,
Although its non-conventional, that should not cause any spinning...

I would still favor EndSomeMethod over ar.AsyncWaitHandle.WaitOne.

My understanding is that the EndSomeMethod call will clean up any resources
that may have been used (such as the WaitHandle itself). Plus it ensures any
return value or Exception is returned to your process. I understand that the
EndSomeMethod should be called even when using the callback as you
originally were. Unfortunately I don't have links to where I got this
impression...

Hope this helps
Jay

<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
|
| Oh, actually, what I do is this:
|
| foreach(IAsyncResult ar in results)
| ar.AsyncWaitHandle.WaitOne();
|
| So presumably it doesn't entail the spining CPU - but just raises an
| event and waits until complete.
|
|
|
|
| Jay B. Harlow [MVP - Outlook] wrote:
| > jabailo,
| > | So, I put the IAsyncResult into the array list and then call the
| > | IsCompleted() method in a while loop on each element.
| > As Dmytro suggests: This is a "bad" idea as you are burning CPU cycles
| > polling IsCompleted, calling EndSomeMethod causes your loop to wait on a
| > WaitHandle under the covers, which is much friendlier.
| >
| > The sample I gave should work with minimal effort.
| >
| > Hope this helps
| > Jay
| >
| > <ja*****@texeme.com> wrote in message
news:42**************@texeme.com...
| > |
| > |
| > | Ok, after trying a bunch of things, I found that I was being thrown
off
| > | by calling the web service locally from my XP machine via studio.
| > |
| > | Somehow, it didn't have the power to keep up with some many
asynchronous
| > | requests. I then configured the web service to be dynamic in my
| > | client so I could point it to a production deployment running on a w2k
| > | server.
| > |
| > | After that I used a mix of the methods suggested here.
| > |
| > | I used an ArrayList ( great idea, because since I'm reading a file
line
| > | by line, I dont' know in advance how many calls I'm making ).
| > |
| > | I can't use the WaitHandles because it's limited to 64.
| > |
| > | So, I put the IAsyncResult into the array list and then call the
| > | IsCompleted() method in a while loop on each element.
| > |
| > | BillyLiu007 wrote:
| > | > when u got the IAsyncResult
| > | > call this :
| > | >
| > | > ar.AsyncWaitHandle.WaitOne();
| > | > (assume u IAsncResult instance is ar)
| > | >
| > | > it will wait the asnyc call to complete
| > | >
| > | > optioanly , u can call
| > | > ar.IsCompleted() to decide
| >
| >

Nov 23 '05 #19

P: n/a
jabailo,
That seems like extra work to me! :-|

You have 2 extra routines, plus you're creating an extra delegate object for
each line in the file.

Calling BegininsertPolarData & EndinsertPolarData directly seems much
simplier to me:

while((s=sr.ReadLine())!=null)
results.Add(as400.BegininsertPolarData(s, tableString, null, null);

foreach(IAsyncResult ar in results)
as400.EndinsertPolarData(ar);

I don't really see what your extra code is buying you that the above code
gives you?

Hope this helps
Jay
<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
| Actually, I am using both.
|
| I keep the EndInvoke that runs on each thread...so it cleans up the
| thread, on the thread, when it finishes. But the WaitOne lets me use
| the handles, on the System.Thread to determine when each async thread is
| finished.
|
| So my code looks like:
|
| while((s=sr.ReadLine())!=null)
| results.Add(this.as400maketable(s,tableString));
|
| foreach(IAsyncResult ar in results)
| ar.AsyncWaitHandle.WaitOne();
|
| private IAsyncResult as400maketable(string line, string tablename)
| {
| AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
| IAsyncResult ar = as400.BegininsertPolarData(
| line, tablename, delCB, null);
| return ar;
| }
|
| void AsyncCB(IAsyncResult ar)
| {
| as400.EndinsertPolarData(ar);
| }
| ;
|
<<snip>>
Nov 23 '05 #20

P: n/a
jabailo,
That seems like extra work to me! :-|

You have 2 extra routines, plus you're creating an extra delegate object for
each line in the file.

Calling BegininsertPolarData & EndinsertPolarData directly seems much
simplier to me:

while((s=sr.ReadLine())!=null)
results.Add(as400.BegininsertPolarData(s, tableString, null, null);

foreach(IAsyncResult ar in results)
as400.EndinsertPolarData(ar);

I don't really see what your extra code is buying you that the above code
gives you?

Hope this helps
Jay
<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
| Actually, I am using both.
|
| I keep the EndInvoke that runs on each thread...so it cleans up the
| thread, on the thread, when it finishes. But the WaitOne lets me use
| the handles, on the System.Thread to determine when each async thread is
| finished.
|
| So my code looks like:
|
| while((s=sr.ReadLine())!=null)
| results.Add(this.as400maketable(s,tableString));
|
| foreach(IAsyncResult ar in results)
| ar.AsyncWaitHandle.WaitOne();
|
| private IAsyncResult as400maketable(string line, string tablename)
| {
| AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
| IAsyncResult ar = as400.BegininsertPolarData(
| line, tablename, delCB, null);
| return ar;
| }
|
| void AsyncCB(IAsyncResult ar)
| {
| as400.EndinsertPolarData(ar);
| }
| ;
|
<<snip>>
Nov 23 '05 #21

P: n/a

Well, by doing it my way, I can allow any thread to run to completion
and clean up asynchronously before polling it to determine if its finished.

So I use my parallel time more efficiently, and minimize my serial time.
Jay B. Harlow [MVP - Outlook] wrote:
jabailo,
That seems like extra work to me! :-|

You have 2 extra routines, plus you're creating an extra delegate object for
each line in the file.

Calling BegininsertPolarData & EndinsertPolarData directly seems much
simplier to me:

while((s=sr.ReadLine())!=null)
results.Add(as400.BegininsertPolarData(s, tableString, null, null);

foreach(IAsyncResult ar in results)
as400.EndinsertPolarData(ar);

I don't really see what your extra code is buying you that the above code
gives you?

Hope this helps
Jay
<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
| Actually, I am using both.
|
| I keep the EndInvoke that runs on each thread...so it cleans up the
| thread, on the thread, when it finishes. But the WaitOne lets me use
| the handles, on the System.Thread to determine when each async thread is
| finished.
|
| So my code looks like:
|
| while((s=sr.ReadLine())!=null)
| results.Add(this.as400maketable(s,tableString));
|
| foreach(IAsyncResult ar in results)
| ar.AsyncWaitHandle.WaitOne();
|
| private IAsyncResult as400maketable(string line, string tablename)
| {
| AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
| IAsyncResult ar = as400.BegininsertPolarData(
| line, tablename, delCB, null);
| return ar;
| }
|
| void AsyncCB(IAsyncResult ar)
| {
| as400.EndinsertPolarData(ar);
| }
| ;
|
<<snip>>

Nov 23 '05 #22

P: n/a

Well, by doing it my way, I can allow any thread to run to completion
and clean up asynchronously before polling it to determine if its finished.

So I use my parallel time more efficiently, and minimize my serial time.
Jay B. Harlow [MVP - Outlook] wrote:
jabailo,
That seems like extra work to me! :-|

You have 2 extra routines, plus you're creating an extra delegate object for
each line in the file.

Calling BegininsertPolarData & EndinsertPolarData directly seems much
simplier to me:

while((s=sr.ReadLine())!=null)
results.Add(as400.BegininsertPolarData(s, tableString, null, null);

foreach(IAsyncResult ar in results)
as400.EndinsertPolarData(ar);

I don't really see what your extra code is buying you that the above code
gives you?

Hope this helps
Jay
<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
| Actually, I am using both.
|
| I keep the EndInvoke that runs on each thread...so it cleans up the
| thread, on the thread, when it finishes. But the WaitOne lets me use
| the handles, on the System.Thread to determine when each async thread is
| finished.
|
| So my code looks like:
|
| while((s=sr.ReadLine())!=null)
| results.Add(this.as400maketable(s,tableString));
|
| foreach(IAsyncResult ar in results)
| ar.AsyncWaitHandle.WaitOne();
|
| private IAsyncResult as400maketable(string line, string tablename)
| {
| AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
| IAsyncResult ar = as400.BegininsertPolarData(
| line, tablename, delCB, null);
| return ar;
| }
|
| void AsyncCB(IAsyncResult ar)
| {
| as400.EndinsertPolarData(ar);
| }
| ;
|
<<snip>>

Nov 23 '05 #23

P: n/a
Jabailo,
Both methods allow any thread to run to completion. Neither method polls to
determine if its finished per se.

Both methods use parallel time efficiently & both minimize serial time.

The only advantage there may be is "clean up asynchronously", however that
feels like a perceived advantage. I would not use a perceived advantage,
especially when it complicates the code.

Remember the 80/20 rule. That is 80% of the execution time of your program
is spent in 20% of your code. I will optimize (worry about performance,
memory consumption) the 20% once that 20% has been identified & proven to be
a performance problem via profiling (CLR Profiler is one profiling tool).

For info on the 80/20 rule & optimizing only the 20% see Martin Fowler's
article "Yet Another Optimization Article" at
http://martinfowler.com/ieeeSoftware...timization.pdf

Obviously we are going to have to agree to disagree here. As long as you got
what works & you understand it.

Hope this helps
Jay

<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
|
| Well, by doing it my way, I can allow any thread to run to completion
| and clean up asynchronously before polling it to determine if its
finished.
|
| So I use my parallel time more efficiently, and minimize my serial time.
|
|
| Jay B. Harlow [MVP - Outlook] wrote:
| > jabailo,
| > That seems like extra work to me! :-|
| >
| > You have 2 extra routines, plus you're creating an extra delegate object
for
| > each line in the file.
| >
| > Calling BegininsertPolarData & EndinsertPolarData directly seems much
| > simplier to me:
| >
| > while((s=sr.ReadLine())!=null)
| > results.Add(as400.BegininsertPolarData(s, tableString, null,
null);
| >
| > foreach(IAsyncResult ar in results)
| > as400.EndinsertPolarData(ar);
| >
| > I don't really see what your extra code is buying you that the above
code
| > gives you?
| >
| > Hope this helps
| > Jay
| >
| >
| > <ja*****@texeme.com> wrote in message
news:42**************@texeme.com...
| > | Actually, I am using both.
| > |
| > | I keep the EndInvoke that runs on each thread...so it cleans up the
| > | thread, on the thread, when it finishes. But the WaitOne lets me use
| > | the handles, on the System.Thread to determine when each async thread
is
| > | finished.
| > |
| > | So my code looks like:
| > |
| > | while((s=sr.ReadLine())!=null)
| > | results.Add(this.as400maketable(s,tableString));
| > |
| > | foreach(IAsyncResult ar in results)
| > | ar.AsyncWaitHandle.WaitOne();
| > |
| > | private IAsyncResult as400maketable(string line, string tablename)
| > | {
| > | AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
| > | IAsyncResult ar = as400.BegininsertPolarData(
| > | line, tablename, delCB, null);
| > | return ar;
| > | }
| > |
| > | void AsyncCB(IAsyncResult ar)
| > | {
| > | as400.EndinsertPolarData(ar);
| > | }
| > | ;
| > |
| > <<snip>>
| >
| >
Nov 23 '05 #24

P: n/a
Jabailo,
Both methods allow any thread to run to completion. Neither method polls to
determine if its finished per se.

Both methods use parallel time efficiently & both minimize serial time.

The only advantage there may be is "clean up asynchronously", however that
feels like a perceived advantage. I would not use a perceived advantage,
especially when it complicates the code.

Remember the 80/20 rule. That is 80% of the execution time of your program
is spent in 20% of your code. I will optimize (worry about performance,
memory consumption) the 20% once that 20% has been identified & proven to be
a performance problem via profiling (CLR Profiler is one profiling tool).

For info on the 80/20 rule & optimizing only the 20% see Martin Fowler's
article "Yet Another Optimization Article" at
http://martinfowler.com/ieeeSoftware...timization.pdf

Obviously we are going to have to agree to disagree here. As long as you got
what works & you understand it.

Hope this helps
Jay

<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
|
| Well, by doing it my way, I can allow any thread to run to completion
| and clean up asynchronously before polling it to determine if its
finished.
|
| So I use my parallel time more efficiently, and minimize my serial time.
|
|
| Jay B. Harlow [MVP - Outlook] wrote:
| > jabailo,
| > That seems like extra work to me! :-|
| >
| > You have 2 extra routines, plus you're creating an extra delegate object
for
| > each line in the file.
| >
| > Calling BegininsertPolarData & EndinsertPolarData directly seems much
| > simplier to me:
| >
| > while((s=sr.ReadLine())!=null)
| > results.Add(as400.BegininsertPolarData(s, tableString, null,
null);
| >
| > foreach(IAsyncResult ar in results)
| > as400.EndinsertPolarData(ar);
| >
| > I don't really see what your extra code is buying you that the above
code
| > gives you?
| >
| > Hope this helps
| > Jay
| >
| >
| > <ja*****@texeme.com> wrote in message
news:42**************@texeme.com...
| > | Actually, I am using both.
| > |
| > | I keep the EndInvoke that runs on each thread...so it cleans up the
| > | thread, on the thread, when it finishes. But the WaitOne lets me use
| > | the handles, on the System.Thread to determine when each async thread
is
| > | finished.
| > |
| > | So my code looks like:
| > |
| > | while((s=sr.ReadLine())!=null)
| > | results.Add(this.as400maketable(s,tableString));
| > |
| > | foreach(IAsyncResult ar in results)
| > | ar.AsyncWaitHandle.WaitOne();
| > |
| > | private IAsyncResult as400maketable(string line, string tablename)
| > | {
| > | AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
| > | IAsyncResult ar = as400.BegininsertPolarData(
| > | line, tablename, delCB, null);
| > | return ar;
| > | }
| > |
| > | void AsyncCB(IAsyncResult ar)
| > | {
| > | as400.EndinsertPolarData(ar);
| > | }
| > | ;
| > |
| > <<snip>>
| >
| >
Nov 23 '05 #25

P: n/a
Dmytro Lapshyn [MVP] wrote:
Hi,

I'd keep an array of the async delegates themselves and call EndInvoke
on each of the delegates in a loop. Thus, you won't be wasting CPU
cycles on polling the array of IAsyncResult references in a loop.


The limit on that is 64.

Nov 23 '05 #26

P: n/a
Dmytro Lapshyn [MVP] wrote:
Hi,

I'd keep an array of the async delegates themselves and call EndInvoke
on each of the delegates in a loop. Thus, you won't be wasting CPU
cycles on polling the array of IAsyncResult references in a loop.


The limit on that is 64.

Nov 23 '05 #27

P: n/a
At a time (because it's the WaitForMultipleObjects API limitation), but not
for a sequential poll, I guess.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
Dmytro Lapshyn [MVP] wrote:
Hi,

I'd keep an array of the async delegates themselves and call EndInvoke on
each of the delegates in a loop. Thus, you won't be wasting CPU cycles on
polling the array of IAsyncResult references in a loop.


The limit on that is 64.


Nov 23 '05 #28

P: n/a
At a time (because it's the WaitForMultipleObjects API limitation), but not
for a sequential poll, I guess.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
Dmytro Lapshyn [MVP] wrote:
Hi,

I'd keep an array of the async delegates themselves and call EndInvoke on
each of the delegates in a loop. Thus, you won't be wasting CPU cycles on
polling the array of IAsyncResult references in a loop.


The limit on that is 64.


Nov 23 '05 #29

P: n/a
Dmytro Lapshyn [MVP] wrote:
At a time (because it's the WaitForMultipleObjects API limitation), but
not for a sequential poll, I guess.


Someone suggested launching them in blocks.

So you could launch 64, wait for the callback, and so on.

Still -- to me -- with a powerful dual proc web server, I would expect that
it would be able to handle hundreds of thousands of calls to a web service
simultaneously ( just like serving hundreds of thousands of web pages ).

--
Texeme Textcasting Technology
http://www.texeme.com
Nov 23 '05 #30

P: n/a
Dmytro Lapshyn [MVP] wrote:
At a time (because it's the WaitForMultipleObjects API limitation), but
not for a sequential poll, I guess.


Someone suggested launching them in blocks.

So you could launch 64, wait for the callback, and so on.

Still -- to me -- with a powerful dual proc web server, I would expect that
it would be able to handle hundreds of thousands of calls to a web service
simultaneously ( just like serving hundreds of thousands of web pages ).

--
Texeme Textcasting Technology
http://www.texeme.com
Nov 23 '05 #31

This discussion thread is closed

Replies have been disabled for this discussion.