I have to implement a Delay Queue in C# as there is no standard implementation of delay queue present in the C#. I am looking to use System.Threading.Timer
for implementing delayed enqueue of a node.
public class DelayQueue<T>
{
private Queue queue<T> = new Queue<T>();
public void Enqueue(Object object)
{
this.queue.Enqueue(object as T);
}
public void Enqueue(T node, TimeSpan dueTime)
{
new System.Threading.Timer(this.Enqueue, node, dueTime, -1);
}
.
.
.
}
This approach looks fine to me but since I am new to C#(from C background), I want someones opinion that whether it is the right way or are there any better and more effective methods of doing the same?