Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to accomplish this pseudo-code in C# in .NET4.5?

         parallelQueue.attemptDequeueFirstItem(item)
             success -> ( doAsyncTask(item).Success(UpdateDatabase) )
              -> repeat until dequeue attempt fails

If we don't use a loop, can an item be dequeued from a parallel queue, which if successful results in an action that uses the dequeued item, and then also in another dequeue attempt, and another action, over and over, until the queue is empty?

share|improve this question
    
2  
@gnat: I don't understand why this wouldn't be germane. It's asking about a design pattern. "problems that you face while in front of your whiteboard designing your project. Everything that can be considered part of the SDLC,...." – TR888 Jan 27 at 20:40
1  
Use a ConcurrentQueue. (there's a code sample at the bottom of that page). – Robert Harvey Jan 27 at 20:50
    
@Robert Harvey: Thanks! The Action example with Parallel.Invoke at the end of that code was what exactly what I was looking for! Can such an Action contain an await? – TR888 Jan 28 at 10:35
    
The Parallel.Invoke should already be calling the actions asynchronously. The WriteLine() at the bottom of that example "awaits" the result (via the interlocked) anyway. – Robert Harvey Jan 28 at 15:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.