I\'m going to use lots of tasks running on my application. Each bunch of tasks is running for some reason. I would like to name these tasks so when I watch the Parallel Tasks wi
public class NamesTask {
readonly Queue _taskqueue = new Queue();
private readonly object _queueLock = new object();
public Task RunTask(Action action) {
//incoming task must be queued as soon as it arrives
var inComingTask = new Task(action);
lock (_queueLock) {
_taskqueue.Enqueue(inComingTask);
}
return Task.Factory.StartNew(() => {
//run all actions one by one..
while (true) {
lock (_queueLock) { //only one task must be performed at a
if (_taskqueue.Count == 0) return;
var outTask = _taskqueue.Dequeue();
outTask.Start();
outTask.Wait();
Console.WriteLine("done....");
}
}
});
}
}