Reputation: 20080
I need to implement in C# 4.0 a logic where an operation might be either executed immediately or put in a Queue waiting that a certain network service becomes available.
What is the best approach to implement such an operation? Is it having a thread-safe queue of Function and a polling consumer that consumes these operations only when the resource is available?
Is there any library or example for implementing similar features?
Upvotes: 0
Views: 102
Reputation: 5140
We can have producer consumer approach with plenty of implementation out. In addition, .NET Concurrent
namespace also have BlockingCollection<T>
or ConcurrentQueue<T>
. However, it seems the challenge is not to implement producer consumer pattern but to wait in the Queue
until some resource is available (network service in your case). This is more of a non-deterministic situation, where you have no idea when the resource will be ready to consume. This challenge can be addressed through having a queue with persistence. Eg: Microsoft's Message Queue (MSMQ)
with private/public queue.
Upvotes: 1