Hope this helps
Jay
| 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
| >
message
| > | > | 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
| > |
| > | | > ||
| > || 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
| > || >
| > || >
| > || > | > || > |
| > || > |
| > || > | 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