473,395 Members | 1,680 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,395 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 2841
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.