Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a website that goes out and queries/consumes 12 different Webservices. Some are SOAP, some URL-REST. Right now the code is set up like a Rolodex, as one Webservice result is returned the next request is fired off. Been reading up on threads and am wondering if this is a good way to go with consuming Web services or is there another avenue I should look at. Webservice results are usually pretty fast but the way the site is working now If one webservice is slow or down it slows the whole process down. If I go to use of threads my main concern is how do know when the treads are finished individually so I can process and display all the results.

Thank You.

What I have tried:

just starting out and looking into threads. Need advice or direction.
Posted
Updated 5-Aug-19 10:44am

The modern (and recommended) way of doing things is using Tasks, see: Task Class (System.Threading.Tasks) | Microsoft Docs[^]
If you want to know what is so great about Tasks, read this series of CodeProject articles:
Task Parallel Library: 1 of n[^]

You can use Task.IsCompleted to check if a task is finished.
 
Share this answer
 
v3
Use tasks (System.Threading.Tasks) instead of threads, that way you won't necessarily even allocate a thread for an operation.

For example, a lot of your services are IO bound - waiting for HTTP request response cycles.

You can do a kernel wait on that, suspending it, and running other code without creating a separate thread. (Windows handles it internally, through IOCP and .NET gives you the ability to use it via tasks)

You don't need to worry about it if you do it this way in a server application, generally. If you're already scaling well with your synchronous model this way should be great for you.

Rick Zeeland posted first so accept his if you were to accept either of ours, but I wanted to give you a little bit of background on tasks
 
Share this answer
 
Add callbacks for each service's "completed" event. Start all services.

In each callback, set an indicator that that service has completed. At the same time, check all other "service" indicators. When all indicators are set, all services have run, and the last callback can trigger the "all completed" event.

How to: Call WCF Service Operations Asynchronously | Microsoft Docs[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900