473,325 Members | 2,671 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,325 software developers and data experts.

Waiting for async webservices to finish.



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
30 2833
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
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
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
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


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


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
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
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
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
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

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

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

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

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
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
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
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
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
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
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

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

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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
by: jabailo | last post by:
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.