I'd like some clarification on code I didn't do and have to modify in a service.
Here's some parts of the code of the service
private Thread _thread;
private ConcurrentQueue<Task> _tasks = new ConcurrentQueue<Task>();
private Task _runningTask = null;
protected override void OnStart(string[] args)
{
_thread = new Thread(WorkerThreadFunc);
_thread.IsBackground = true;
_thread.Start();
}
private void WorkerThreadFunc()
{
InitDb();
while (!_shutdownEvent.WaitOne(1000))
{
if (_runningTask == null || _runningTask.IsCompleted)
{
Task task;
if (_tasks.TryDequeue(out task))
{
_runningTask = task;
_runningTask.Start();
}
}
}
}
private void RunReport(int reportID)
{
var task = new Task(id =>
{
//Task code
}, reportID);
_tasks.Enqueue(task);
}
And so, this all works well
The thing is, I want to add other tasks to the task queue, but I don't have any ID to give them (the task in the code runs a report and uses the reportID, but the other tasks aren't linked to one report in particular).
Is there a way to create a Task without giving it an ID (which I doubt), or is there something i'm completely missing ?