You can execute parsing asynchronously:
See BeginInvoke, EndInvoke, IAsyncResult in MSDN
Main Topics
Browse All TopicsHi,
I would like to have a parser object which I submit url array string[] and it does the work asynchronously.
how do I get the answers after all the threads have finished. Let's say that I will expect an array of results for example the string[] containing the error code of each page 200, 404, 500 etc.. each retrieved.
How do I make sure all the work is finished and how to continue on the main thread (UI).
Thanks,
Ilan
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Well I expected some kind of thread pool, let's say I'm using my parser with maxThreads = 50 threads.
When the consumer sends string[] urls, it calls a thread on each url , let's say Parse(url) is call asynchronously
Each thread have the same callback.
How do I write the code in the callback to wait for all to finish and when all is done notify the consumer with callback.
thanks,
Ilan
I presume you would be doing async requests, which means threading would be done for you.
On each response you could flag progress. Once all responses are received you could signal for the GUI to continue. I personally woudn't have the GUI wait but just disable it until all responses are received. This way it will still be responsive.
I've done it by using a List to keep track of request in progress. Once a reques completes/errors it is removed from the list. The GUIlistens to the list (say by using a BindingList and the ListChanged event) and once it is empty it re-enables its controls.
Business Accounts
Answer for Membership
by: numberkruncherPosted on 2009-04-25 at 18:18:19ID: 24234160
In C# you can use the "lock" feature to synchronise access to an object. Use this statement around all blocks of code which access shared resources. The lock statement blocks other threads from accessing the shared variable/property/object until the other thread leaves the lock statement.
en-us/libr ary/c5kehk cz(VS.80). aspx
The following link provides a detailed explanation of the "lock" statement:
http://msdn.microsoft.com/
Select allOpen in new window