Posts

Showing posts from June, 2016

Task Queue Revisited

Several years back, I wrote about  A Simple Task Queue and made a sort of promise that if I got time, I would enhance it a bit.

Here is my enhanced version.

public class TaskQueue { public delegate void TaskDelegate(); public TaskDelegate TaskDlgt { get; private set; } public TaskQueue(TaskDelegate dlgt) : this(dlgt, null) { } public TaskQueue(TaskDelegate dlgt, Queue<TaskDelegate> q) { _Q = q; TaskDlgt = dlgt; } public void Enqueue() { lock(_Q) { if(Busy) _Q.Enqueue(TaskDlgt); else { Busy = true; TaskDlgt.BeginInvoke(TaskCallback, TaskDlgt); } } } private void NextTask() { TaskDelegate dlgt; lock (_Q) { if (_Q.Count > 0) { dlgt …