473,413 Members | 1,833 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,413 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 22 '05 #1
53 1953
Hi,

If you invoke the Web services asynchronously, you should have a reference
to each async delegate. Therefore, you can call EndInvoke on each delegate
to wait while the async process finishes. While the calling thread will be
frozen during the waiting, this will not prevent the Web service from
completing its task.

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


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 22 '05 #2
Hi,

If you invoke the Web services asynchronously, you should have a reference
to each async delegate. Therefore, you can call EndInvoke on each delegate
to wait while the async process finishes. While the calling thread will be
frozen during the waiting, this will not prevent the Web service from
completing its task.

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


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 22 '05 #3
"ja*****@texeme.com" <ja*****@texeme.com> wrote in
news:fP********************@speakeasy.net:
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?


They will continue to process.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
Nov 22 '05 #4
"ja*****@texeme.com" <ja*****@texeme.com> wrote in
news:fP********************@speakeasy.net:
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?


They will continue to process.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
Nov 22 '05 #5
"ja*****@texeme.com" <ja*****@texeme.com> wrote in
news:fP********************@speakeasy.net:
microsoft.public.dotnet.framework.remoting
microsoft.public.dotnet.framework.webservices,
microsoft.public.dotnet.general
microsoft.public.dotnet.languages.csharp


Well at least you set a follow up. But please dont cross post. Surely you can pick on of these
as most appropriate:

http://www.hower.org/kudzu/dotnet/ne...guidelines.iwp


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Empower ASP.NET with IntraWeb
http://www.atozed.com/IntraWeb/
Nov 22 '05 #6
"ja*****@texeme.com" <ja*****@texeme.com> wrote in
news:fP********************@speakeasy.net:
microsoft.public.dotnet.framework.remoting
microsoft.public.dotnet.framework.webservices,
microsoft.public.dotnet.general
microsoft.public.dotnet.languages.csharp


Well at least you set a follow up. But please dont cross post. Surely you can pick on of these
as most appropriate:

http://www.hower.org/kudzu/dotnet/ne...guidelines.iwp


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Empower ASP.NET with IntraWeb
http://www.atozed.com/IntraWeb/
Nov 22 '05 #7
Chad Z. Hower aka Kudzu wrote:
"ja*****@texeme.com" <ja*****@texeme.com> wrote in
news:fP********************@speakeasy.net:
microsoft.public.dotnet.framework.remoting
microsoft.public.dotnet.framework.webservices,
microsoft.public.dotnet.general
microsoft.public.dotnet.languages.csharp
Well at least you set a follow up. But please dont cross post. Surely you
can pick on of these as most appropriate:

http://www.hower.org/kudzu/dotnet/ne...guidelines.iwp


Huh?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Empower ASP.NET with IntraWeb
http://www.atozed.com/IntraWeb/


--
Texeme Textcasting Technology
http://www.texeme.com
Nov 22 '05 #8
Chad Z. Hower aka Kudzu wrote:
"ja*****@texeme.com" <ja*****@texeme.com> wrote in
news:fP********************@speakeasy.net:
microsoft.public.dotnet.framework.remoting
microsoft.public.dotnet.framework.webservices,
microsoft.public.dotnet.general
microsoft.public.dotnet.languages.csharp
Well at least you set a follow up. But please dont cross post. Surely you
can pick on of these as most appropriate:

http://www.hower.org/kudzu/dotnet/ne...guidelines.iwp


Huh?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Empower ASP.NET with IntraWeb
http://www.atozed.com/IntraWeb/


--
Texeme Textcasting Technology
http://www.texeme.com
Nov 22 '05 #9
Dmytro Lapshyn [MVP] wrote:
Hi,

If you invoke the Web services asynchronously, you should have a reference
to each async delegate. Therefore, you can call EndInvoke on each delegate
to wait while the async process finishes. While the calling thread will be
frozen during the waiting, this will not prevent the Web service from
completing its task.


Does calling EndInvoke make it uncessary to use the WaitForAll method of the
IAsynchResult handler?

--
Texeme Textcasting Technology
http://www.texeme.com
Nov 22 '05 #10
Dmytro Lapshyn [MVP] wrote:
Hi,

If you invoke the Web services asynchronously, you should have a reference
to each async delegate. Therefore, you can call EndInvoke on each delegate
to wait while the async process finishes. While the calling thread will be
frozen during the waiting, this will not prevent the Web service from
completing its task.


Does calling EndInvoke make it uncessary to use the WaitForAll method of the
IAsynchResult handler?

--
Texeme Textcasting Technology
http://www.texeme.com
Nov 22 '05 #11
jabailo,
The "easiest" way is to put the IAsyncResult that each of the web service
Begin* calls returns into a collection (ArrayList for example) then call the
web service End* calls for each entry in the collection.

Something like:

YourWebService ws = new YourWebService();

ArrayList results = new ArrayList();

String line = null;
while (line != null)
{
results.Add(ws.BeginSomeMethod(line, null, null));
line = reader.ReadLine();
}

foreach(IAsyncResult result in results)
{
ws.EndSomeMethod(result);
}

You may want to wrap the EndSomeMethod in a try/catch within the loop as it
may throw an exception...

Hope this helps
Jay
<ja*****@texeme.com> wrote in message
news:fP********************@speakeasy.net...
|
|
| 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 22 '05 #12
jabailo,
The "easiest" way is to put the IAsyncResult that each of the web service
Begin* calls returns into a collection (ArrayList for example) then call the
web service End* calls for each entry in the collection.

Something like:

YourWebService ws = new YourWebService();

ArrayList results = new ArrayList();

String line = null;
while (line != null)
{
results.Add(ws.BeginSomeMethod(line, null, null));
line = reader.ReadLine();
}

foreach(IAsyncResult result in results)
{
ws.EndSomeMethod(result);
}

You may want to wrap the EndSomeMethod in a try/catch within the loop as it
may throw an exception...

Hope this helps
Jay
<ja*****@texeme.com> wrote in message
news:fP********************@speakeasy.net...
|
|
| 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 22 '05 #13
"ja*****@texeme.com" <ja*****@texeme.com> wrote in
news:qt********************@speakeasy.net:
http://www.hower.org/kudzu/dotnet/ne...guidelines.iwp


Huh?


See the sectino about cross posting.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/
Nov 22 '05 #14
"ja*****@texeme.com" <ja*****@texeme.com> wrote in
news:qt********************@speakeasy.net:
http://www.hower.org/kudzu/dotnet/ne...guidelines.iwp


Huh?


See the sectino about cross posting.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/
Nov 22 '05 #15
Chad Z. Hower aka Kudzu wrote:
"ja*****@texeme.com" <ja*****@texeme.com> wrote in
news:qt********************@speakeasy.net:
http://www.hower.org/kudzu/dotnet/ne...guidelines.iwp
Huh?

See the sectino about cross posting.


Maybe I wasn't clear enough:

"Please get off my ass."



--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/

Nov 22 '05 #16
Chad Z. Hower aka Kudzu wrote:
"ja*****@texeme.com" <ja*****@texeme.com> wrote in
news:qt********************@speakeasy.net:
http://www.hower.org/kudzu/dotnet/ne...guidelines.iwp
Huh?

See the sectino about cross posting.


Maybe I wasn't clear enough:

"Please get off my ass."



--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/

Nov 22 '05 #17

I'm a little confused about what the ws.EndSomeMethod accomplishes.

For example, say I make 100 calls to a webservice asynchronously.

Say call 66, 72 and 98 run /extremely/ slow.

Ok, so after the while() loop, I have 100 threads, 97 have made a
successful call, 3 have not finished.

Then I run the foreach loop...what does ws.EndSomeMethod do? Does it
wait, sequentially, for each method call to finish and then check the
next method call?

What if I do it this way (the way I'm doing it in my code now). Will
the code "wait" until all those threads have finished before moving on?
Or is that why I need a .WaitForAll()?:
while((s=sr.ReadLine())!=null)
{
this.as400maketable(s,tableString);
}

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

void AsyncCB(IAsyncResult ar)
{
as400.EndinsertPolarData(ar);
}
Jay B. Harlow [MVP - Outlook] wrote:
jabailo,
The "easiest" way is to put the IAsyncResult that each of the web service
Begin* calls returns into a collection (ArrayList for example) then call the
web service End* calls for each entry in the collection.

Something like:

YourWebService ws = new YourWebService();

ArrayList results = new ArrayList();

String line = null;
while (line != null)
{
results.Add(ws.BeginSomeMethod(line, null, null));
line = reader.ReadLine();
}

foreach(IAsyncResult result in results)
{
ws.EndSomeMethod(result);
}

You may want to wrap the EndSomeMethod in a try/catch within the loop as it
may throw an exception...

Hope this helps
Jay
<ja*****@texeme.com> wrote in message
news:fP********************@speakeasy.net...
|
|
| 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 22 '05 #18

I'm a little confused about what the ws.EndSomeMethod accomplishes.

For example, say I make 100 calls to a webservice asynchronously.

Say call 66, 72 and 98 run /extremely/ slow.

Ok, so after the while() loop, I have 100 threads, 97 have made a
successful call, 3 have not finished.

Then I run the foreach loop...what does ws.EndSomeMethod do? Does it
wait, sequentially, for each method call to finish and then check the
next method call?

What if I do it this way (the way I'm doing it in my code now). Will
the code "wait" until all those threads have finished before moving on?
Or is that why I need a .WaitForAll()?:
while((s=sr.ReadLine())!=null)
{
this.as400maketable(s,tableString);
}

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

void AsyncCB(IAsyncResult ar)
{
as400.EndinsertPolarData(ar);
}
Jay B. Harlow [MVP - Outlook] wrote:
jabailo,
The "easiest" way is to put the IAsyncResult that each of the web service
Begin* calls returns into a collection (ArrayList for example) then call the
web service End* calls for each entry in the collection.

Something like:

YourWebService ws = new YourWebService();

ArrayList results = new ArrayList();

String line = null;
while (line != null)
{
results.Add(ws.BeginSomeMethod(line, null, null));
line = reader.ReadLine();
}

foreach(IAsyncResult result in results)
{
ws.EndSomeMethod(result);
}

You may want to wrap the EndSomeMethod in a try/catch within the loop as it
may throw an exception...

Hope this helps
Jay
<ja*****@texeme.com> wrote in message
news:fP********************@speakeasy.net...
|
|
| 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 22 '05 #19
"ja*****@texeme.com" <ja*****@texeme.com> wrote in news:42**************@texeme.com:
Maybe I wasn't clear enough:

"Please get off my ass."


Well Im sure you'll receive a lot of help with your questions with posts like that.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
Nov 22 '05 #20
"ja*****@texeme.com" <ja*****@texeme.com> wrote in news:42**************@texeme.com:
Maybe I wasn't clear enough:

"Please get off my ass."


Well Im sure you'll receive a lot of help with your questions with posts like that.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
Nov 22 '05 #21
jabailo,
| Then I run the foreach loop...what does ws.EndSomeMethod do? Does it
| wait, sequentially, for each method call to finish and then check the
| next method call?
It waits sequentially for each method to finish, the foreach itself checks
for the next method.

| Say call 66, 72 and 98 run /extremely/ slow.
The ws.EndSomeMethod will wait for 66 to finish. Seeing as 67 to 71 finished
"a long time" before 66 they return "immediately" from the ws.EndSomeMethod.
If 72 takes longer then 66, then ws.EndSomeMethod will wait for it,
otherwise it returns "immediately" also, same with 98... The net effect is
the for each only really waits as long the longest running method, plus some
very minor overhead...
| What if I do it this way (the way I'm doing it in my code now). Will
| the code "wait" until all those threads have finished before moving on?
| Or is that why I need a .WaitForAll()?:

The for each I showed is effectively a .WaitForAll. I understand that
WaitHandle.WaitAll has an implicit limitation of 64, which is an OS
limitation.

The "problem" with the call back, as you are finding, is that there is no
"obvious" way to indicate to the main thread that all the workers are
finished, where as with the for each the main thread waits for each worker
individually...

In a project where I am using ThreadPool.QueueUserWorkItem I increment a
count when I queue an item, then decrement the count when the item finishes.
You may be able to use a similar technique with the callbacks, where you
release an Manual or Auto Reset Event, to release the main thread when the
count reaches zero... However I would go with the for each over

Hope this helps
Jay

<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
|
| I'm a little confused about what the ws.EndSomeMethod accomplishes.
|
| For example, say I make 100 calls to a webservice asynchronously.
|
| Say call 66, 72 and 98 run /extremely/ slow.
|
| Ok, so after the while() loop, I have 100 threads, 97 have made a
| successful call, 3 have not finished.
|
| Then I run the foreach loop...what does ws.EndSomeMethod do? Does it
| wait, sequentially, for each method call to finish and then check the
| next method call?
|
| What if I do it this way (the way I'm doing it in my code now). Will
| the code "wait" until all those threads have finished before moving on?
| Or is that why I need a .WaitForAll()?:
|
|
| while((s=sr.ReadLine())!=null)
| {
| this.as400maketable(s,tableString);
| }
|
| private void as400maketable(string line, string tablename)
| {
| AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
| as400.BegininsertPolarData(line, tablename, delCB, null);
| }
|
| void AsyncCB(IAsyncResult ar)
| {
| as400.EndinsertPolarData(ar);
| }
|
|
| Jay B. Harlow [MVP - Outlook] wrote:
| > jabailo,
| > The "easiest" way is to put the IAsyncResult that each of the web
service
| > Begin* calls returns into a collection (ArrayList for example) then call
the
| > web service End* calls for each entry in the collection.
| >
| > Something like:
| >
| > YourWebService ws = new YourWebService();
| >
| > ArrayList results = new ArrayList();
| >
| > String line = null;
| > while (line != null)
| > {
| > results.Add(ws.BeginSomeMethod(line, null, null));
| > line = reader.ReadLine();
| > }
| >
| > foreach(IAsyncResult result in results)
| > {
| > ws.EndSomeMethod(result);
| > }
| >
| > You may want to wrap the EndSomeMethod in a try/catch within the loop as
it
| > may throw an exception...
| >
| > Hope this helps
| > Jay
| >
| >
| > <ja*****@texeme.com> wrote in message
| > news:fP********************@speakeasy.net...
| > |
| > |
| > | 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 22 '05 #22
jabailo,
| Then I run the foreach loop...what does ws.EndSomeMethod do? Does it
| wait, sequentially, for each method call to finish and then check the
| next method call?
It waits sequentially for each method to finish, the foreach itself checks
for the next method.

| Say call 66, 72 and 98 run /extremely/ slow.
The ws.EndSomeMethod will wait for 66 to finish. Seeing as 67 to 71 finished
"a long time" before 66 they return "immediately" from the ws.EndSomeMethod.
If 72 takes longer then 66, then ws.EndSomeMethod will wait for it,
otherwise it returns "immediately" also, same with 98... The net effect is
the for each only really waits as long the longest running method, plus some
very minor overhead...
| What if I do it this way (the way I'm doing it in my code now). Will
| the code "wait" until all those threads have finished before moving on?
| Or is that why I need a .WaitForAll()?:

The for each I showed is effectively a .WaitForAll. I understand that
WaitHandle.WaitAll has an implicit limitation of 64, which is an OS
limitation.

The "problem" with the call back, as you are finding, is that there is no
"obvious" way to indicate to the main thread that all the workers are
finished, where as with the for each the main thread waits for each worker
individually...

In a project where I am using ThreadPool.QueueUserWorkItem I increment a
count when I queue an item, then decrement the count when the item finishes.
You may be able to use a similar technique with the callbacks, where you
release an Manual or Auto Reset Event, to release the main thread when the
count reaches zero... However I would go with the for each over

Hope this helps
Jay

<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
|
| I'm a little confused about what the ws.EndSomeMethod accomplishes.
|
| For example, say I make 100 calls to a webservice asynchronously.
|
| Say call 66, 72 and 98 run /extremely/ slow.
|
| Ok, so after the while() loop, I have 100 threads, 97 have made a
| successful call, 3 have not finished.
|
| Then I run the foreach loop...what does ws.EndSomeMethod do? Does it
| wait, sequentially, for each method call to finish and then check the
| next method call?
|
| What if I do it this way (the way I'm doing it in my code now). Will
| the code "wait" until all those threads have finished before moving on?
| Or is that why I need a .WaitForAll()?:
|
|
| while((s=sr.ReadLine())!=null)
| {
| this.as400maketable(s,tableString);
| }
|
| private void as400maketable(string line, string tablename)
| {
| AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
| as400.BegininsertPolarData(line, tablename, delCB, null);
| }
|
| void AsyncCB(IAsyncResult ar)
| {
| as400.EndinsertPolarData(ar);
| }
|
|
| Jay B. Harlow [MVP - Outlook] wrote:
| > jabailo,
| > The "easiest" way is to put the IAsyncResult that each of the web
service
| > Begin* calls returns into a collection (ArrayList for example) then call
the
| > web service End* calls for each entry in the collection.
| >
| > Something like:
| >
| > YourWebService ws = new YourWebService();
| >
| > ArrayList results = new ArrayList();
| >
| > String line = null;
| > while (line != null)
| > {
| > results.Add(ws.BeginSomeMethod(line, null, null));
| > line = reader.ReadLine();
| > }
| >
| > foreach(IAsyncResult result in results)
| > {
| > ws.EndSomeMethod(result);
| > }
| >
| > You may want to wrap the EndSomeMethod in a try/catch within the loop as
it
| > may throw an exception...
| >
| > Hope this helps
| > Jay
| >
| >
| > <ja*****@texeme.com> wrote in message
| > news:fP********************@speakeasy.net...
| > |
| > |
| > | 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 22 '05 #23
If you are waiting for it to finish, use a sync (not async) method call.

<ja*****@texeme.com> wrote in message
news:fP********************@speakeasy.net...


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 22 '05 #24
If you are waiting for it to finish, use a sync (not async) method call.

<ja*****@texeme.com> wrote in message
news:fP********************@speakeasy.net...


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 22 '05 #25

But I want them to run in parallel.

Using sync, it would be a worse case wait.

Using async, it's only as long as the longest thread.

Christopher Schipper wrote:
If you are waiting for it to finish, use a sync (not async) method call.

<ja*****@texeme.com> wrote in message
news:fP********************@speakeasy.net...

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 22 '05 #26

But I want them to run in parallel.

Using sync, it would be a worse case wait.

Using async, it's only as long as the longest thread.

Christopher Schipper wrote:
If you are waiting for it to finish, use a sync (not async) method call.

<ja*****@texeme.com> wrote in message
news:fP********************@speakeasy.net...

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 22 '05 #27
Doh!
|| Say call 66, 72 and 98 run /extremely/ slow.
| The ws.EndSomeMethod will wait for 66 to finish. Seeing as 67 to 71
finished
| "a long time" before 66 they return "immediately" from the
ws.EndSomeMethod.
That should read: The ws.EndSomeMethod will wait for 1 to 65 to finish, then
wait as long as it takes for 66 to finish. Seeing as 67 to 71...

Hope this helps
Jay

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uV**************@TK2MSFTNGP09.phx.gbl...
| jabailo,
|| Then I run the foreach loop...what does ws.EndSomeMethod do? Does it
|| wait, sequentially, for each method call to finish and then check the
|| next method call?
| It waits sequentially for each method to finish, the foreach itself checks
| for the next method.
|
|| Say call 66, 72 and 98 run /extremely/ slow.
| The ws.EndSomeMethod will wait for 66 to finish. Seeing as 67 to 71
finished
| "a long time" before 66 they return "immediately" from the
ws.EndSomeMethod.
| If 72 takes longer then 66, then ws.EndSomeMethod will wait for it,
| otherwise it returns "immediately" also, same with 98... The net effect is
| the for each only really waits as long the longest running method, plus
some
| very minor overhead...
|
|
|| What if I do it this way (the way I'm doing it in my code now). Will
|| the code "wait" until all those threads have finished before moving on?
|| Or is that why I need a .WaitForAll()?:
|
| The for each I showed is effectively a .WaitForAll. I understand that
| WaitHandle.WaitAll has an implicit limitation of 64, which is an OS
| limitation.
|
| The "problem" with the call back, as you are finding, is that there is no
| "obvious" way to indicate to the main thread that all the workers are
| finished, where as with the for each the main thread waits for each worker
| individually...
|
| In a project where I am using ThreadPool.QueueUserWorkItem I increment a
| count when I queue an item, then decrement the count when the item
finishes.
| You may be able to use a similar technique with the callbacks, where you
| release an Manual or Auto Reset Event, to release the main thread when the
| count reaches zero... However I would go with the for each over
|
| Hope this helps
| Jay
|
| <ja*****@texeme.com> wrote in message news:42**************@texeme.com...
||
|| I'm a little confused about what the ws.EndSomeMethod accomplishes.
||
|| For example, say I make 100 calls to a webservice asynchronously.
||
|| Say call 66, 72 and 98 run /extremely/ slow.
||
|| Ok, so after the while() loop, I have 100 threads, 97 have made a
|| successful call, 3 have not finished.
||
|| Then I run the foreach loop...what does ws.EndSomeMethod do? Does it
|| wait, sequentially, for each method call to finish and then check the
|| next method call?
||
|| What if I do it this way (the way I'm doing it in my code now). Will
|| the code "wait" until all those threads have finished before moving on?
|| Or is that why I need a .WaitForAll()?:
||
||
|| while((s=sr.ReadLine())!=null)
|| {
|| this.as400maketable(s,tableString);
|| }
||
|| private void as400maketable(string line, string tablename)
|| {
|| AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
|| as400.BegininsertPolarData(line, tablename, delCB, null);
|| }
||
|| void AsyncCB(IAsyncResult ar)
|| {
|| as400.EndinsertPolarData(ar);
|| }
||
||
|| Jay B. Harlow [MVP - Outlook] wrote:
|| > jabailo,
|| > The "easiest" way is to put the IAsyncResult that each of the web
| service
|| > Begin* calls returns into a collection (ArrayList for example) then
call
| the
|| > web service End* calls for each entry in the collection.
|| >
|| > Something like:
|| >
|| > YourWebService ws = new YourWebService();
|| >
|| > ArrayList results = new ArrayList();
|| >
|| > String line = null;
|| > while (line != null)
|| > {
|| > results.Add(ws.BeginSomeMethod(line, null, null));
|| > line = reader.ReadLine();
|| > }
|| >
|| > foreach(IAsyncResult result in results)
|| > {
|| > ws.EndSomeMethod(result);
|| > }
|| >
|| > You may want to wrap the EndSomeMethod in a try/catch within the loop
as
| it
|| > may throw an exception...
|| >
|| > Hope this helps
|| > Jay
|| >
|| >
|| > <ja*****@texeme.com> wrote in message
|| > news:fP********************@speakeasy.net...
|| > |
|| > |
|| > | 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 22 '05 #28
Doh!
|| Say call 66, 72 and 98 run /extremely/ slow.
| The ws.EndSomeMethod will wait for 66 to finish. Seeing as 67 to 71
finished
| "a long time" before 66 they return "immediately" from the
ws.EndSomeMethod.
That should read: The ws.EndSomeMethod will wait for 1 to 65 to finish, then
wait as long as it takes for 66 to finish. Seeing as 67 to 71...

Hope this helps
Jay

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uV**************@TK2MSFTNGP09.phx.gbl...
| jabailo,
|| Then I run the foreach loop...what does ws.EndSomeMethod do? Does it
|| wait, sequentially, for each method call to finish and then check the
|| next method call?
| It waits sequentially for each method to finish, the foreach itself checks
| for the next method.
|
|| Say call 66, 72 and 98 run /extremely/ slow.
| The ws.EndSomeMethod will wait for 66 to finish. Seeing as 67 to 71
finished
| "a long time" before 66 they return "immediately" from the
ws.EndSomeMethod.
| If 72 takes longer then 66, then ws.EndSomeMethod will wait for it,
| otherwise it returns "immediately" also, same with 98... The net effect is
| the for each only really waits as long the longest running method, plus
some
| very minor overhead...
|
|
|| What if I do it this way (the way I'm doing it in my code now). Will
|| the code "wait" until all those threads have finished before moving on?
|| Or is that why I need a .WaitForAll()?:
|
| The for each I showed is effectively a .WaitForAll. I understand that
| WaitHandle.WaitAll has an implicit limitation of 64, which is an OS
| limitation.
|
| The "problem" with the call back, as you are finding, is that there is no
| "obvious" way to indicate to the main thread that all the workers are
| finished, where as with the for each the main thread waits for each worker
| individually...
|
| In a project where I am using ThreadPool.QueueUserWorkItem I increment a
| count when I queue an item, then decrement the count when the item
finishes.
| You may be able to use a similar technique with the callbacks, where you
| release an Manual or Auto Reset Event, to release the main thread when the
| count reaches zero... However I would go with the for each over
|
| Hope this helps
| Jay
|
| <ja*****@texeme.com> wrote in message news:42**************@texeme.com...
||
|| I'm a little confused about what the ws.EndSomeMethod accomplishes.
||
|| For example, say I make 100 calls to a webservice asynchronously.
||
|| Say call 66, 72 and 98 run /extremely/ slow.
||
|| Ok, so after the while() loop, I have 100 threads, 97 have made a
|| successful call, 3 have not finished.
||
|| Then I run the foreach loop...what does ws.EndSomeMethod do? Does it
|| wait, sequentially, for each method call to finish and then check the
|| next method call?
||
|| What if I do it this way (the way I'm doing it in my code now). Will
|| the code "wait" until all those threads have finished before moving on?
|| Or is that why I need a .WaitForAll()?:
||
||
|| while((s=sr.ReadLine())!=null)
|| {
|| this.as400maketable(s,tableString);
|| }
||
|| private void as400maketable(string line, string tablename)
|| {
|| AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
|| as400.BegininsertPolarData(line, tablename, delCB, null);
|| }
||
|| void AsyncCB(IAsyncResult ar)
|| {
|| as400.EndinsertPolarData(ar);
|| }
||
||
|| Jay B. Harlow [MVP - Outlook] wrote:
|| > jabailo,
|| > The "easiest" way is to put the IAsyncResult that each of the web
| service
|| > Begin* calls returns into a collection (ArrayList for example) then
call
| the
|| > web service End* calls for each entry in the collection.
|| >
|| > Something like:
|| >
|| > YourWebService ws = new YourWebService();
|| >
|| > ArrayList results = new ArrayList();
|| >
|| > String line = null;
|| > while (line != null)
|| > {
|| > results.Add(ws.BeginSomeMethod(line, null, null));
|| > line = reader.ReadLine();
|| > }
|| >
|| > foreach(IAsyncResult result in results)
|| > {
|| > ws.EndSomeMethod(result);
|| > }
|| >
|| > You may want to wrap the EndSomeMethod in a try/catch within the loop
as
| it
|| > may throw an exception...
|| >
|| > Hope this helps
|| > Jay
|| >
|| >
|| > <ja*****@texeme.com> wrote in message
|| > news:fP********************@speakeasy.net...
|| > |
|| > |
|| > | 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 22 '05 #29
Jay B. Harlow [MVP - Outlook] wrote:
Doh!
|| Say call 66, 72 and 98 run /extremely/ slow.
| The ws.EndSomeMethod will wait for 66 to finish. Seeing as 67 to 71
finished
| "a long time" before 66 they return "immediately" from the
ws.EndSomeMethod.
That should read: The ws.EndSomeMethod will wait for 1 to 65 to finish,
then wait as long as it takes for 66 to finish. Seeing as 67 to 71...
How about the way I implemented it.

Will each webservice pause the main path of execution long enough to
complete?


Hope this helps
Jay

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uV**************@TK2MSFTNGP09.phx.gbl...
| jabailo,
|| Then I run the foreach loop...what does ws.EndSomeMethod do? Does it
|| wait, sequentially, for each method call to finish and then check the
|| next method call?
| It waits sequentially for each method to finish, the foreach itself
| checks for the next method.
|
|| Say call 66, 72 and 98 run /extremely/ slow.
| The ws.EndSomeMethod will wait for 66 to finish. Seeing as 67 to 71
finished
| "a long time" before 66 they return "immediately" from the
ws.EndSomeMethod.
| If 72 takes longer then 66, then ws.EndSomeMethod will wait for it,
| otherwise it returns "immediately" also, same with 98... The net effect
| is the for each only really waits as long the longest running method,
| plus
some
| very minor overhead...
|
|
|| What if I do it this way (the way I'm doing it in my code now). Will
|| the code "wait" until all those threads have finished before moving on?
|| Or is that why I need a .WaitForAll()?:
|
| The for each I showed is effectively a .WaitForAll. I understand that
| WaitHandle.WaitAll has an implicit limitation of 64, which is an OS
| limitation.
|
| The "problem" with the call back, as you are finding, is that there is
| no "obvious" way to indicate to the main thread that all the workers are
| finished, where as with the for each the main thread waits for each
| worker individually...
|
| In a project where I am using ThreadPool.QueueUserWorkItem I increment a
| count when I queue an item, then decrement the count when the item
finishes.
| You may be able to use a similar technique with the callbacks, where you
| release an Manual or Auto Reset Event, to release the main thread when
| the count reaches zero... However I would go with the for each over
|
| Hope this helps
| Jay
|
| <ja*****@texeme.com> wrote in message
| news:42**************@texeme.com...
||
|| I'm a little confused about what the ws.EndSomeMethod accomplishes.
||
|| For example, say I make 100 calls to a webservice asynchronously.
||
|| Say call 66, 72 and 98 run /extremely/ slow.
||
|| Ok, so after the while() loop, I have 100 threads, 97 have made a
|| successful call, 3 have not finished.
||
|| Then I run the foreach loop...what does ws.EndSomeMethod do? Does it
|| wait, sequentially, for each method call to finish and then check the
|| next method call?
||
|| What if I do it this way (the way I'm doing it in my code now). Will
|| the code "wait" until all those threads have finished before moving on?
|| Or is that why I need a .WaitForAll()?:
||
||
|| while((s=sr.ReadLine())!=null)
|| {
|| this.as400maketable(s,tableString);
|| }
||
|| private void as400maketable(string line, string tablename)
|| {
|| AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
|| as400.BegininsertPolarData(line, tablename, delCB, null);
|| }
||
|| void AsyncCB(IAsyncResult ar)
|| {
|| as400.EndinsertPolarData(ar);
|| }
||
||
|| Jay B. Harlow [MVP - Outlook] wrote:
|| > jabailo,
|| > The "easiest" way is to put the IAsyncResult that each of the web
| service
|| > Begin* calls returns into a collection (ArrayList for example) then
call
| the
|| > web service End* calls for each entry in the collection.
|| >
|| > Something like:
|| >
|| > YourWebService ws = new YourWebService();
|| >
|| > ArrayList results = new ArrayList();
|| >
|| > String line = null;
|| > while (line != null)
|| > {
|| > results.Add(ws.BeginSomeMethod(line, null, null));
|| > line = reader.ReadLine();
|| > }
|| >
|| > foreach(IAsyncResult result in results)
|| > {
|| > ws.EndSomeMethod(result);
|| > }
|| >
|| > You may want to wrap the EndSomeMethod in a try/catch within the loop
as
| it
|| > may throw an exception...
|| >
|| > Hope this helps
|| > Jay
|| >
|| >
|| > <ja*****@texeme.com> wrote in message
|| > news:fP********************@speakeasy.net...
|| > |
|| > |
|| > | 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
|| >
|| >
|
|


--
Texeme Textcasting Technology
http://www.texeme.com
Nov 22 '05 #30
Jabailo,
| How about the way I implemented it.
|
| Will each webservice pause the main path of execution long enough to
| complete?

No. When you use a callback as you did, the main thread will immediately
continue with what it was doing.

My understanding is the callback is executed on the same thread as the
asynchronous method was executed on.

Hope this helps
Jay
<ja*****@texeme.com> wrote in message
news:kf********************@speakeasy.net...
| Jay B. Harlow [MVP - Outlook] wrote:
|
| > Doh!
| > || Say call 66, 72 and 98 run /extremely/ slow.
| > | The ws.EndSomeMethod will wait for 66 to finish. Seeing as 67 to 71
| > finished
| > | "a long time" before 66 they return "immediately" from the
| > ws.EndSomeMethod.
| > That should read: The ws.EndSomeMethod will wait for 1 to 65 to finish,
| > then wait as long as it takes for 66 to finish. Seeing as 67 to 71...
|
| How about the way I implemented it.
|
| Will each webservice pause the main path of execution long enough to
| complete?
|
|
| >
| > Hope this helps
| > Jay
| >
| > "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in
message
| > news:uV**************@TK2MSFTNGP09.phx.gbl...
| > | jabailo,
| > || Then I run the foreach loop...what does ws.EndSomeMethod do? Does
it
| > || wait, sequentially, for each method call to finish and then check the
| > || next method call?
| > | It waits sequentially for each method to finish, the foreach itself
| > | checks for the next method.
| > |
| > || Say call 66, 72 and 98 run /extremely/ slow.
| > | The ws.EndSomeMethod will wait for 66 to finish. Seeing as 67 to 71
| > finished
| > | "a long time" before 66 they return "immediately" from the
| > ws.EndSomeMethod.
| > | If 72 takes longer then 66, then ws.EndSomeMethod will wait for it,
| > | otherwise it returns "immediately" also, same with 98... The net
effect
| > | is the for each only really waits as long the longest running method,
| > | plus
| > some
| > | very minor overhead...
| > |
| > |
| > || What if I do it this way (the way I'm doing it in my code now).
Will
| > || the code "wait" until all those threads have finished before moving
on?
| > || Or is that why I need a .WaitForAll()?:
| > |
| > | The for each I showed is effectively a .WaitForAll. I understand that
| > | WaitHandle.WaitAll has an implicit limitation of 64, which is an OS
| > | limitation.
| > |
| > | The "problem" with the call back, as you are finding, is that there is
| > | no "obvious" way to indicate to the main thread that all the workers
are
| > | finished, where as with the for each the main thread waits for each
| > | worker individually...
| > |
| > | In a project where I am using ThreadPool.QueueUserWorkItem I increment
a
| > | count when I queue an item, then decrement the count when the item
| > finishes.
| > | You may be able to use a similar technique with the callbacks, where
you
| > | release an Manual or Auto Reset Event, to release the main thread when
| > | the count reaches zero... However I would go with the for each over
| > |
| > | Hope this helps
| > | Jay
| > |
| > | <ja*****@texeme.com> wrote in message
| > | news:42**************@texeme.com...
| > ||
| > || I'm a little confused about what the ws.EndSomeMethod accomplishes.
| > ||
| > || For example, say I make 100 calls to a webservice asynchronously.
| > ||
| > || Say call 66, 72 and 98 run /extremely/ slow.
| > ||
| > || Ok, so after the while() loop, I have 100 threads, 97 have made a
| > || successful call, 3 have not finished.
| > ||
| > || Then I run the foreach loop...what does ws.EndSomeMethod do? Does
it
| > || wait, sequentially, for each method call to finish and then check the
| > || next method call?
| > ||
| > || What if I do it this way (the way I'm doing it in my code now).
Will
| > || the code "wait" until all those threads have finished before moving
on?
| > || Or is that why I need a .WaitForAll()?:
| > ||
| > ||
| > || while((s=sr.ReadLine())!=null)
| > || {
| > || this.as400maketable(s,tableString);
| > || }
| > ||
| > || private void as400maketable(string line, string tablename)
| > || {
| > || AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
| > || as400.BegininsertPolarData(line, tablename, delCB, null);
| > || }
| > ||
| > || void AsyncCB(IAsyncResult ar)
| > || {
| > || as400.EndinsertPolarData(ar);
| > || }
| > ||
| > ||
| > || Jay B. Harlow [MVP - Outlook] wrote:
| > || > jabailo,
| > || > The "easiest" way is to put the IAsyncResult that each of the web
| > | service
| > || > Begin* calls returns into a collection (ArrayList for example) then
| > call
| > | the
| > || > web service End* calls for each entry in the collection.
| > || >
| > || > Something like:
| > || >
| > || > YourWebService ws = new YourWebService();
| > || >
| > || > ArrayList results = new ArrayList();
| > || >
| > || > String line = null;
| > || > while (line != null)
| > || > {
| > || > results.Add(ws.BeginSomeMethod(line, null, null));
| > || > line = reader.ReadLine();
| > || > }
| > || >
| > || > foreach(IAsyncResult result in results)
| > || > {
| > || > ws.EndSomeMethod(result);
| > || > }
| > || >
| > || > You may want to wrap the EndSomeMethod in a try/catch within the
loop
| > as
| > | it
| > || > may throw an exception...
| > || >
| > || > Hope this helps
| > || > Jay
| > || >
| > || >
| > || > <ja*****@texeme.com> wrote in message
| > || > news:fP********************@speakeasy.net...
| > || > |
| > || > |
| > || > | 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
| > || >
| > || >
| > |
| > |
|
| --
| Texeme Textcasting Technology
| http://www.texeme.com
Nov 22 '05 #31
Jay B. Harlow [MVP - Outlook] wrote:
Jabailo,
| How about the way I implemented it.
|
| Will each webservice pause the main path of execution long enough to
| complete?

No. When you use a callback as you did, the main thread will immediately
continue with what it was doing.

My understanding is the callback is executed on the same thread as the
asynchronous method was executed on.
I could probably put the callback responses into a global static
ArrayList then and use your foreach method there.

I wonder if the WaitAll can take an ArrayList as well as an array of
AsyncCallback...


Hope this helps
Jay
<ja*****@texeme.com> wrote in message
news:kf********************@speakeasy.net...
| Jay B. Harlow [MVP - Outlook] wrote:
|
| > Doh!
| > || Say call 66, 72 and 98 run /extremely/ slow.
| > | The ws.EndSomeMethod will wait for 66 to finish. Seeing as 67 to 71
| > finished
| > | "a long time" before 66 they return "immediately" from the
| > ws.EndSomeMethod.
| > That should read: The ws.EndSomeMethod will wait for 1 to 65 to finish,
| > then wait as long as it takes for 66 to finish. Seeing as 67 to 71...
|
| How about the way I implemented it.
|
| Will each webservice pause the main path of execution long enough to
| complete?
|
|
| >
| > Hope this helps
| > Jay
| >
| > "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in
message
| > news:uV**************@TK2MSFTNGP09.phx.gbl...
| > | jabailo,
| > || Then I run the foreach loop...what does ws.EndSomeMethod do? Does
it
| > || wait, sequentially, for each method call to finish and then check the
| > || next method call?
| > | It waits sequentially for each method to finish, the foreach itself
| > | checks for the next method.
| > |
| > || Say call 66, 72 and 98 run /extremely/ slow.
| > | The ws.EndSomeMethod will wait for 66 to finish. Seeing as 67 to 71
| > finished
| > | "a long time" before 66 they return "immediately" from the
| > ws.EndSomeMethod.
| > | If 72 takes longer then 66, then ws.EndSomeMethod will wait for it,
| > | otherwise it returns "immediately" also, same with 98... The net
effect
| > | is the for each only really waits as long the longest running method,
| > | plus
| > some
| > | very minor overhead...
| > |
| > |
| > || What if I do it this way (the way I'm doing it in my code now).
Will
| > || the code "wait" until all those threads have finished before moving
on?
| > || Or is that why I need a .WaitForAll()?:
| > |
| > | The for each I showed is effectively a .WaitForAll. I understand that
| > | WaitHandle.WaitAll has an implicit limitation of 64, which is an OS
| > | limitation.
| > |
| > | The "problem" with the call back, as you are finding, is that there is
| > | no "obvious" way to indicate to the main thread that all the workers
are
| > | finished, where as with the for each the main thread waits for each
| > | worker individually...
| > |
| > | In a project where I am using ThreadPool.QueueUserWorkItem I increment
a
| > | count when I queue an item, then decrement the count when the item
| > finishes.
| > | You may be able to use a similar technique with the callbacks, where
you
| > | release an Manual or Auto Reset Event, to release the main thread when
| > | the count reaches zero... However I would go with the for each over
| > |
| > | Hope this helps
| > | Jay
| > |
| > | <ja*****@texeme.com> wrote in message
| > | news:42**************@texeme.com...
| > ||
| > || I'm a little confused about what the ws.EndSomeMethod accomplishes.
| > ||
| > || For example, say I make 100 calls to a webservice asynchronously.
| > ||
| > || Say call 66, 72 and 98 run /extremely/ slow.
| > ||
| > || Ok, so after the while() loop, I have 100 threads, 97 have made a
| > || successful call, 3 have not finished.
| > ||
| > || Then I run the foreach loop...what does ws.EndSomeMethod do? Does
it
| > || wait, sequentially, for each method call to finish and then check the
| > || next method call?
| > ||
| > || What if I do it this way (the way I'm doing it in my code now).
Will
| > || the code "wait" until all those threads have finished before moving
on?
| > || Or is that why I need a .WaitForAll()?:
| > ||
| > ||
| > || while((s=sr.ReadLine())!=null)
| > || {
| > || this.as400maketable(s,tableString);
| > || }
| > ||
| > || private void as400maketable(string line, string tablename)
| > || {
| > || AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
| > || as400.BegininsertPolarData(line, tablename, delCB, null);
| > || }
| > ||
| > || void AsyncCB(IAsyncResult ar)
| > || {
| > || as400.EndinsertPolarData(ar);
| > || }
| > ||
| > ||
| > || Jay B. Harlow [MVP - Outlook] wrote:
| > || > jabailo,
| > || > The "easiest" way is to put the IAsyncResult that each of the web
| > | service
| > || > Begin* calls returns into a collection (ArrayList for example) then
| > call
| > | the
| > || > web service End* calls for each entry in the collection.
| > || >
| > || > Something like:
| > || >
| > || > YourWebService ws = new YourWebService();
| > || >
| > || > ArrayList results = new ArrayList();
| > || >
| > || > String line = null;
| > || > while (line != null)
| > || > {
| > || > results.Add(ws.BeginSomeMethod(line, null, null));
| > || > line = reader.ReadLine();
| > || > }
| > || >
| > || > foreach(IAsyncResult result in results)
| > || > {
| > || > ws.EndSomeMethod(result);
| > || > }
| > || >
| > || > You may want to wrap the EndSomeMethod in a try/catch within the
loop
| > as
| > | it
| > || > may throw an exception...
| > || >
| > || > Hope this helps
| > || > Jay
| > || >
| > || >
| > || > <ja*****@texeme.com> wrote in message
| > || > news:fP********************@speakeasy.net...
| > || > |
| > || > |
| > || > | 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
| > || >
| > || >
| > |
| > |
|
| --
| Texeme Textcasting Technology
| http://www.texeme.com

Nov 22 '05 #32
The Thread.Sleep only effects the current thread. The web service itself is
running in a completely different process, if not physically on a different
machine. So sleeping the thread shouldn't have any effect on the executing
of the web service itself.

You can also use the IsCompleted property to determine if the web service
has finished.

Hope this helps,

Richard Rosenheim
<ja*****@texeme.com> wrote in message
news:fP********************@speakeasy.net...


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 22 '05 #33
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 22 '05 #34
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 22 '05 #35

Ok, I'm going to try it this way.

I wonder if there's a more efficient way to convert all those array
types into one another (!?)

ArrayList results = new ArrayList();

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

sr.Close();

IAsyncResult[] ar
= (IAsyncResult[]) results.ToArray(typeof(IAsyncResult));

WaitHandle[] wh = new WaitHandle[ar.Length];

for(int i=0; i<ar.Length; i++)wh[i]=ar[i].AsyncWaitHandle;

WaitHandle.WaitAll(wh);

ja*****@texeme.com wrote:
Jay B. Harlow [MVP - Outlook] wrote:
Jabailo,
| How about the way I implemented it.
|
| Will each webservice pause the main path of execution long enough to
| complete?

No. When you use a callback as you did, the main thread will
immediately continue with what it was doing.

My understanding is the callback is executed on the same thread as the
asynchronous method was executed on.

I could probably put the callback responses into a global static
ArrayList then and use your foreach method there.

I wonder if the WaitAll can take an ArrayList as well as an array of
AsyncCallback...


Hope this helps
Jay
<ja*****@texeme.com> wrote in message
news:kf********************@speakeasy.net...
| Jay B. Harlow [MVP - Outlook] wrote:
|
| > Doh!
| > || Say call 66, 72 and 98 run /extremely/ slow.
| > | The ws.EndSomeMethod will wait for 66 to finish. Seeing as 67 to 71
| > finished
| > | "a long time" before 66 they return "immediately" from the
| > ws.EndSomeMethod.
| > That should read: The ws.EndSomeMethod will wait for 1 to 65 to
finish,
| > then wait as long as it takes for 66 to finish. Seeing as 67 to 71...
|
| How about the way I implemented it.
|
| Will each webservice pause the main path of execution long enough to
| complete?
|
|
| >
| > Hope this helps
| > Jay
| >
| > "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in
message
| > news:uV**************@TK2MSFTNGP09.phx.gbl...
| > | jabailo,
| > || Then I run the foreach loop...what does ws.EndSomeMethod do?
Does it
| > || wait, sequentially, for each method call to finish and then
check the
| > || next method call?
| > | It waits sequentially for each method to finish, the foreach itself
| > | checks for the next method.
| > |
| > || Say call 66, 72 and 98 run /extremely/ slow.
| > | The ws.EndSomeMethod will wait for 66 to finish. Seeing as 67 to 71
| > finished
| > | "a long time" before 66 they return "immediately" from the
| > ws.EndSomeMethod.
| > | If 72 takes longer then 66, then ws.EndSomeMethod will wait for it,
| > | otherwise it returns "immediately" also, same with 98... The net
effect
| > | is the for each only really waits as long the longest running
method,
| > | plus
| > some
| > | very minor overhead...
| > |
| > |
| > || What if I do it this way (the way I'm doing it in my code now).
Will
| > || the code "wait" until all those threads have finished before
moving on?
| > || Or is that why I need a .WaitForAll()?:
| > |
| > | The for each I showed is effectively a .WaitForAll. I understand
that
| > | WaitHandle.WaitAll has an implicit limitation of 64, which is an OS
| > | limitation.
| > |
| > | The "problem" with the call back, as you are finding, is that
there is
| > | no "obvious" way to indicate to the main thread that all the
workers are
| > | finished, where as with the for each the main thread waits for each
| > | worker individually...
| > |
| > | In a project where I am using ThreadPool.QueueUserWorkItem I
increment a
| > | count when I queue an item, then decrement the count when the item
| > finishes.
| > | You may be able to use a similar technique with the callbacks,
where you
| > | release an Manual or Auto Reset Event, to release the main
thread when
| > | the count reaches zero... However I would go with the for each over
| > |
| > | Hope this helps
| > | Jay
| > |
| > | <ja*****@texeme.com> wrote in message
| > | news:42**************@texeme.com...
| > ||
| > || I'm a little confused about what the ws.EndSomeMethod
accomplishes.
| > ||
| > || For example, say I make 100 calls to a webservice asynchronously.
| > ||
| > || Say call 66, 72 and 98 run /extremely/ slow.
| > ||
| > || Ok, so after the while() loop, I have 100 threads, 97 have made a
| > || successful call, 3 have not finished.
| > ||
| > || Then I run the foreach loop...what does ws.EndSomeMethod do?
Does it
| > || wait, sequentially, for each method call to finish and then
check the
| > || next method call?
| > ||
| > || What if I do it this way (the way I'm doing it in my code now).
Will
| > || the code "wait" until all those threads have finished before
moving on?
| > || Or is that why I need a .WaitForAll()?:
| > ||
| > ||
| > || while((s=sr.ReadLine())!=null)
| > || {
| > || this.as400maketable(s,tableString);
| > || }
| > ||
| > || private void as400maketable(string line, string tablename)
| > || {
| > || AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
| > || as400.BegininsertPolarData(line, tablename, delCB, null);
| > || }
| > ||
| > || void AsyncCB(IAsyncResult ar)
| > || {
| > || as400.EndinsertPolarData(ar);
| > || }
| > ||
| > ||
| > || Jay B. Harlow [MVP - Outlook] wrote:
| > || > jabailo,
| > || > The "easiest" way is to put the IAsyncResult that each of the
web
| > | service
| > || > Begin* calls returns into a collection (ArrayList for
example) then
| > call
| > | the
| > || > web service End* calls for each entry in the collection.
| > || >
| > || > Something like:
| > || >
| > || > YourWebService ws = new YourWebService();
| > || >
| > || > ArrayList results = new ArrayList();
| > || >
| > || > String line = null;
| > || > while (line != null)
| > || > {
| > || > results.Add(ws.BeginSomeMethod(line, null, null));
| > || > line = reader.ReadLine();
| > || > }
| > || >
| > || > foreach(IAsyncResult result in results)
| > || > {
| > || > ws.EndSomeMethod(result);
| > || > }
| > || >
| > || > You may want to wrap the EndSomeMethod in a try/catch within
the loop
| > as
| > | it
| > || > may throw an exception...
| > || >
| > || > Hope this helps
| > || > Jay
| > || >
| > || >
| > || > <ja*****@texeme.com> wrote in message
| > || > news:fP********************@speakeasy.net...
| > || > |
| > || > |
| > || > | 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
| > || >
| > || >
| > |
| > |
|
| -- | Texeme Textcasting Technology
| http://www.texeme.com

Nov 22 '05 #36
Scratch that -- guess I'm doing it your way :D
6/22/2005 3:34:23 PM:System.NotSupportedException: The number of
WaitHandles must be less than or equal to 64.
at System.Threading.WaitHandle.WaitAll(WaitHandle[] waitHandles,
Int32 millisecondsTimeout, Boolean exitContext)
at System.Threading.WaitHandle.WaitAll(WaitHandle[] waitHandles)
at PolarFW.PolarFW.as400insert(String FileName) in c:\documents and
settings\jbailo\my documents\visual studio
projects\cryptserv\psebank\polarfw.cs:line 480


ja*****@texeme.com wrote:

Ok, I'm going to try it this way.

I wonder if there's a more efficient way to convert all those array
types into one another (!?)

ArrayList results = new ArrayList();

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

sr.Close();

IAsyncResult[] ar
= (IAsyncResult[]) results.ToArray(typeof(IAsyncResult));

WaitHandle[] wh = new WaitHandle[ar.Length];

for(int i=0; i<ar.Length; i++)wh[i]=ar[i].AsyncWaitHandle;

WaitHandle.WaitAll(wh);

ja*****@texeme.com wrote:
Jay B. Harlow [MVP - Outlook] wrote:
Jabailo,
| How about the way I implemented it.
|
| Will each webservice pause the main path of execution long enough to
| complete?

No. When you use a callback as you did, the main thread will
immediately continue with what it was doing.

My understanding is the callback is executed on the same thread as
the asynchronous method was executed on.


I could probably put the callback responses into a global static
ArrayList then and use your foreach method there.

I wonder if the WaitAll can take an ArrayList as well as an array of
AsyncCallback...


Hope this helps
Jay
<ja*****@texeme.com> wrote in message
news:kf********************@speakeasy.net...
| Jay B. Harlow [MVP - Outlook] wrote:
|
| > Doh!
| > || Say call 66, 72 and 98 run /extremely/ slow.
| > | The ws.EndSomeMethod will wait for 66 to finish. Seeing as 67
to 71
| > finished
| > | "a long time" before 66 they return "immediately" from the
| > ws.EndSomeMethod.
| > That should read: The ws.EndSomeMethod will wait for 1 to 65 to
finish,
| > then wait as long as it takes for 66 to finish. Seeing as 67 to
71...
|
| How about the way I implemented it.
|
| Will each webservice pause the main path of execution long enough to
| complete?
|
|
| >
| > Hope this helps
| > Jay
| >
| > "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in
message
| > news:uV**************@TK2MSFTNGP09.phx.gbl...
| > | jabailo,
| > || Then I run the foreach loop...what does ws.EndSomeMethod do?
Does it
| > || wait, sequentially, for each method call to finish and then
check the
| > || next method call?
| > | It waits sequentially for each method to finish, the foreach
itself
| > | checks for the next method.
| > |
| > || Say call 66, 72 and 98 run /extremely/ slow.
| > | The ws.EndSomeMethod will wait for 66 to finish. Seeing as 67
to 71
| > finished
| > | "a long time" before 66 they return "immediately" from the
| > ws.EndSomeMethod.
| > | If 72 takes longer then 66, then ws.EndSomeMethod will wait for
it,
| > | otherwise it returns "immediately" also, same with 98... The
net effect
| > | is the for each only really waits as long the longest running
method,
| > | plus
| > some
| > | very minor overhead...
| > |
| > |
| > || What if I do it this way (the way I'm doing it in my code
now). Will
| > || the code "wait" until all those threads have finished before
moving on?
| > || Or is that why I need a .WaitForAll()?:
| > |
| > | The for each I showed is effectively a .WaitForAll. I
understand that
| > | WaitHandle.WaitAll has an implicit limitation of 64, which is
an OS
| > | limitation.
| > |
| > | The "problem" with the call back, as you are finding, is that
there is
| > | no "obvious" way to indicate to the main thread that all the
workers are
| > | finished, where as with the for each the main thread waits for
each
| > | worker individually...
| > |
| > | In a project where I am using ThreadPool.QueueUserWorkItem I
increment a
| > | count when I queue an item, then decrement the count when the item
| > finishes.
| > | You may be able to use a similar technique with the callbacks,
where you
| > | release an Manual or Auto Reset Event, to release the main
thread when
| > | the count reaches zero... However I would go with the for each
over
| > |
| > | Hope this helps
| > | Jay
| > |
| > | <ja*****@texeme.com> wrote in message
| > | news:42**************@texeme.com...
| > ||
| > || I'm a little confused about what the ws.EndSomeMethod
accomplishes.
| > ||
| > || For example, say I make 100 calls to a webservice asynchronously.
| > ||
| > || Say call 66, 72 and 98 run /extremely/ slow.
| > ||
| > || Ok, so after the while() loop, I have 100 threads, 97 have made a
| > || successful call, 3 have not finished.
| > ||
| > || Then I run the foreach loop...what does ws.EndSomeMethod do?
Does it
| > || wait, sequentially, for each method call to finish and then
check the
| > || next method call?
| > ||
| > || What if I do it this way (the way I'm doing it in my code
now). Will
| > || the code "wait" until all those threads have finished before
moving on?
| > || Or is that why I need a .WaitForAll()?:
| > ||
| > ||
| > || while((s=sr.ReadLine())!=null)
| > || {
| > || this.as400maketable(s,tableString);
| > || }
| > ||
| > || private void as400maketable(string line, string tablename)
| > || {
| > || AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
| > || as400.BegininsertPolarData(line, tablename, delCB, null);
| > || }
| > ||
| > || void AsyncCB(IAsyncResult ar)
| > || {
| > || as400.EndinsertPolarData(ar);
| > || }
| > ||
| > ||
| > || Jay B. Harlow [MVP - Outlook] wrote:
| > || > jabailo,
| > || > The "easiest" way is to put the IAsyncResult that each of
the web
| > | service
| > || > Begin* calls returns into a collection (ArrayList for
example) then
| > call
| > | the
| > || > web service End* calls for each entry in the collection.
| > || >
| > || > Something like:
| > || >
| > || > YourWebService ws = new YourWebService();
| > || >
| > || > ArrayList results = new ArrayList();
| > || >
| > || > String line = null;
| > || > while (line != null)
| > || > {
| > || > results.Add(ws.BeginSomeMethod(line, null, null));
| > || > line = reader.ReadLine();
| > || > }
| > || >
| > || > foreach(IAsyncResult result in results)
| > || > {
| > || > ws.EndSomeMethod(result);
| > || > }
| > || >
| > || > You may want to wrap the EndSomeMethod in a try/catch within
the loop
| > as
| > | it
| > || > may throw an exception...
| > || >
| > || > Hope this helps
| > || > Jay
| > || >
| > || >
| > || > <ja*****@texeme.com> wrote in message
| > || > news:fP********************@speakeasy.net...
| > || > |
| > || > |
| > || > | 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
| > || >
| > || >
| > |
| > |
|
| -- | Texeme Textcasting Technology
| http://www.texeme.com

Nov 22 '05 #37

You method didn't quite seem to work either.

It through errors when trying to iterate through results.

I'm wondering if the completion of the BeginSomeMethod removes the
IAsyncHandle -- so no EndSomeMethod is possible on some elements of results.

Jay B. Harlow [MVP - Outlook] wrote:
jabailo,
The "easiest" way is to put the IAsyncResult that each of the web service
Begin* calls returns into a collection (ArrayList for example) then call the
web service End* calls for each entry in the collection.

Something like:

YourWebService ws = new YourWebService();

ArrayList results = new ArrayList();

String line = null;
while (line != null)
{
results.Add(ws.BeginSomeMethod(line, null, null));
line = reader.ReadLine();
}

foreach(IAsyncResult result in results)
{
ws.EndSomeMethod(result);
}

You may want to wrap the EndSomeMethod in a try/catch within the loop as it
may throw an exception...

Hope this helps
Jay
<ja*****@texeme.com> wrote in message
news:fP********************@speakeasy.net...
|
|
| 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 22 '05 #38


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 22 '05 #39
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 22 '05 #40
jabailo,
That seems like a lot of work, when this will do the same thing:

| ArrayList results = new ArrayList();
|
| while((s=sr.ReadLine())!=null)
| {
| results.Add(as400.BegininsertPolarData(s, tableString, null, null));
| }
|
| sr.Close();

foreach(IAsyncResult result in results)
{
ws.EndSomeMethod(result);
}

As you avoid 2 temporary arrays (GC friendly), plus you avoid copying
elements between the 3 arrays (time friendly).

Also as you found the WaitHandle.WaitAll(wh) has a 64 WaitHandle limit, if
your file is more then 64 lines you will have a problem, the above foreach
will not!

In both cases the Main thread will have waited until all the asynchronous
results are finished.

Hope this helps
Jay

<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
|
| Ok, I'm going to try it this way.
|
| I wonder if there's a more efficient way to convert all those array
| types into one another (!?)
|
| ArrayList results = new ArrayList();
|
| while((s=sr.ReadLine())!=null)
| {
| results.Add(as400.BegininsertPolarData(s, tableString, null, null));
| }
|
| sr.Close();
|
| IAsyncResult[] ar
| = (IAsyncResult[]) results.ToArray(typeof(IAsyncResult));
|
| WaitHandle[] wh = new WaitHandle[ar.Length];
|
| for(int i=0; i<ar.Length; i++)wh[i]=ar[i].AsyncWaitHandle;
|
| WaitHandle.WaitAll(wh);
|
|
|
|
|
| ja*****@texeme.com wrote:
| > Jay B. Harlow [MVP - Outlook] wrote:
| >
| >> Jabailo,
| >> | How about the way I implemented it.
| >> |
| >> | Will each webservice pause the main path of execution long enough to
| >> | complete?
| >>
| >> No. When you use a callback as you did, the main thread will
| >> immediately continue with what it was doing.
| >>
| >> My understanding is the callback is executed on the same thread as the
| >> asynchronous method was executed on.
| >
| >
| > I could probably put the callback responses into a global static
| > ArrayList then and use your foreach method there.
| >
| > I wonder if the WaitAll can take an ArrayList as well as an array of
| > AsyncCallback...
| >
| >
| >>
| >> Hope this helps
| >> Jay
| >>
| >>
| >> <ja*****@texeme.com> wrote in message
| >> news:kf********************@speakeasy.net...
| >> | Jay B. Harlow [MVP - Outlook] wrote:
| >> |
| >> | > Doh!
| >> | > || Say call 66, 72 and 98 run /extremely/ slow.
| >> | > | The ws.EndSomeMethod will wait for 66 to finish. Seeing as 67 to
71
| >> | > finished
| >> | > | "a long time" before 66 they return "immediately" from the
| >> | > ws.EndSomeMethod.
| >> | > That should read: The ws.EndSomeMethod will wait for 1 to 65 to
| >> finish,
| >> | > then wait as long as it takes for 66 to finish. Seeing as 67 to
71...
| >> |
| >> | How about the way I implemented it.
| >> |
| >> | Will each webservice pause the main path of execution long enough to
| >> | complete?
| >> |
| >> |
| >> | >
| >> | > Hope this helps
| >> | > Jay
| >> | >
| >> | > "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in
| >> message
| >> | > news:uV**************@TK2MSFTNGP09.phx.gbl...
| >> | > | jabailo,
| >> | > || Then I run the foreach loop...what does ws.EndSomeMethod do?
| >> Does it
| >> | > || wait, sequentially, for each method call to finish and then
| >> check the
| >> | > || next method call?
| >> | > | It waits sequentially for each method to finish, the foreach
itself
| >> | > | checks for the next method.
| >> | > |
| >> | > || Say call 66, 72 and 98 run /extremely/ slow.
| >> | > | The ws.EndSomeMethod will wait for 66 to finish. Seeing as 67 to
71
| >> | > finished
| >> | > | "a long time" before 66 they return "immediately" from the
| >> | > ws.EndSomeMethod.
| >> | > | If 72 takes longer then 66, then ws.EndSomeMethod will wait for
it,
| >> | > | otherwise it returns "immediately" also, same with 98... The net
| >> effect
| >> | > | is the for each only really waits as long the longest running
| >> method,
| >> | > | plus
| >> | > some
| >> | > | very minor overhead...
| >> | > |
| >> | > |
| >> | > || What if I do it this way (the way I'm doing it in my code now).
| >> Will
| >> | > || the code "wait" until all those threads have finished before
| >> moving on?
| >> | > || Or is that why I need a .WaitForAll()?:
| >> | > |
| >> | > | The for each I showed is effectively a .WaitForAll. I understand
| >> that
| >> | > | WaitHandle.WaitAll has an implicit limitation of 64, which is an
OS
| >> | > | limitation.
| >> | > |
| >> | > | The "problem" with the call back, as you are finding, is that
| >> there is
| >> | > | no "obvious" way to indicate to the main thread that all the
| >> workers are
| >> | > | finished, where as with the for each the main thread waits for
each
| >> | > | worker individually...
| >> | > |
| >> | > | In a project where I am using ThreadPool.QueueUserWorkItem I
| >> increment a
| >> | > | count when I queue an item, then decrement the count when the
item
| >> | > finishes.
| >> | > | You may be able to use a similar technique with the callbacks,
| >> where you
| >> | > | release an Manual or Auto Reset Event, to release the main
| >> thread when
| >> | > | the count reaches zero... However I would go with the for each
over
| >> | > |
| >> | > | Hope this helps
| >> | > | Jay
| >> | > |
| >> | > | <ja*****@texeme.com> wrote in message
| >> | > | news:42**************@texeme.com...
| >> | > ||
| >> | > || I'm a little confused about what the ws.EndSomeMethod
| >> accomplishes.
| >> | > ||
| >> | > || For example, say I make 100 calls to a webservice
asynchronously.
| >> | > ||
| >> | > || Say call 66, 72 and 98 run /extremely/ slow.
| >> | > ||
| >> | > || Ok, so after the while() loop, I have 100 threads, 97 have made
a
| >> | > || successful call, 3 have not finished.
| >> | > ||
| >> | > || Then I run the foreach loop...what does ws.EndSomeMethod do?
| >> Does it
| >> | > || wait, sequentially, for each method call to finish and then
| >> check the
| >> | > || next method call?
| >> | > ||
| >> | > || What if I do it this way (the way I'm doing it in my code now).
| >> Will
| >> | > || the code "wait" until all those threads have finished before
| >> moving on?
| >> | > || Or is that why I need a .WaitForAll()?:
| >> | > ||
| >> | > ||
| >> | > || while((s=sr.ReadLine())!=null)
| >> | > || {
| >> | > || this.as400maketable(s,tableString);
| >> | > || }
| >> | > ||
| >> | > || private void as400maketable(string line, string tablename)
| >> | > || {
| >> | > || AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
| >> | > || as400.BegininsertPolarData(line, tablename, delCB, null);
| >> | > || }
| >> | > ||
| >> | > || void AsyncCB(IAsyncResult ar)
| >> | > || {
| >> | > || as400.EndinsertPolarData(ar);
| >> | > || }
| >> | > ||
| >> | > ||
| >> | > || Jay B. Harlow [MVP - Outlook] wrote:
| >> | > || > jabailo,
| >> | > || > The "easiest" way is to put the IAsyncResult that each of the
| >> web
| >> | > | service
| >> | > || > Begin* calls returns into a collection (ArrayList for
| >> example) then
| >> | > call
| >> | > | the
| >> | > || > web service End* calls for each entry in the collection.
| >> | > || >
| >> | > || > Something like:
| >> | > || >
| >> | > || > YourWebService ws = new YourWebService();
| >> | > || >
| >> | > || > ArrayList results = new ArrayList();
| >> | > || >
| >> | > || > String line = null;
| >> | > || > while (line != null)
| >> | > || > {
| >> | > || > results.Add(ws.BeginSomeMethod(line, null, null));
| >> | > || > line = reader.ReadLine();
| >> | > || > }
| >> | > || >
| >> | > || > foreach(IAsyncResult result in results)
| >> | > || > {
| >> | > || > ws.EndSomeMethod(result);
| >> | > || > }
| >> | > || >
| >> | > || > You may want to wrap the EndSomeMethod in a try/catch within
| >> the loop
| >> | > as
| >> | > | it
| >> | > || > may throw an exception...
| >> | > || >
| >> | > || > Hope this helps
| >> | > || > Jay
| >> | > || >
| >> | > || >
| >> | > || > <ja*****@texeme.com> wrote in message
| >> | > || > news:fP********************@speakeasy.net...
| >> | > || > |
| >> | > || > |
| >> | > || > | 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
| >> | > || >
| >> | > || >
| >> | > |
| >> | > |
| >> |
| >> | -- | Texeme Textcasting Technology
| >> | http://www.texeme.com
| >>
Nov 22 '05 #41
jabailo,
What specifically was the exception and/or problem?

I've used similar code in VB.NET without any problems. My sample was typed
"from memory" so I could have had a minor typo in translation...

Remember that EndSomeMethod will raise an exception if the remote
asynchronous method threw an exception.

Hope this helps
Jay

<ja*****@texeme.com> wrote in message news:42**************@texeme.com...
|
| You method didn't quite seem to work either.
|
| It through errors when trying to iterate through results.
|
| I'm wondering if the completion of the BeginSomeMethod removes the
| IAsyncHandle -- so no EndSomeMethod is possible on some elements of
results.
|
| Jay B. Harlow [MVP - Outlook] wrote:
| > jabailo,
| > The "easiest" way is to put the IAsyncResult that each of the web
service
| > Begin* calls returns into a collection (ArrayList for example) then call
the
| > web service End* calls for each entry in the collection.
| >
| > Something like:
| >
| > YourWebService ws = new YourWebService();
| >
| > ArrayList results = new ArrayList();
| >
| > String line = null;
| > while (line != null)
| > {
| > results.Add(ws.BeginSomeMethod(line, null, null));
| > line = reader.ReadLine();
| > }
| >
| > foreach(IAsyncResult result in results)
| > {
| > ws.EndSomeMethod(result);
| > }
| >
| > You may want to wrap the EndSomeMethod in a try/catch within the loop as
it
| > may throw an exception...
| >
| > Hope this helps
| > Jay
| >
| >
| > <ja*****@texeme.com> wrote in message
| > news:fP********************@speakeasy.net...
| > |
| > |
| > | 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 22 '05 #42
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 22 '05 #43

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 22 '05 #44

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 22 '05 #45
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 22 '05 #46
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 22 '05 #47
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 22 '05 #48

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 22 '05 #49
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 22 '05 #50

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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.