I just learned about queues in .NET and I have a few questions.
Let's say that I'm building an application that downloads the HTML of pages and then processes it. Here's how I want it to operate:
- A main thread adds URLs to a queue
- This queue is read by two other threads. They "dequeue" a URL and then download the corresponding HTML.
- The HTML is then sent back to the main thread.
- When the HTML arrives in the main thread, it is placed into another queue, handled by another two threads. These threads process the HTML.
- The results of the processing are returned to the main thread.
How can I implement such a scenario without the possibility of a race condition?
Also, what is the best way to pass the information between queues and threads as described above?
Could you give me some sample code?
Thanks!