My current project is using .net 2.0 threading and has a master thread for scheduling 1.File download thread and 2. File Processing Thread. I can restrict the maximum threads to be processed in parallel, say 16 (May be 10 file download and 6 file processing for the already downloaded files). I would like to migrate my code using TPL.
Thread workerThread = null;
switch (Status)
{
case StatusEnum.FileWatchLocked:
workerThread = new Thread(workflowMgr.GetFiles);
break;
case FPFStatusEnum.ProcessLocked:
workerThread = new Thread(workflowMgr.ProcessFiles);
break;
}
lock (_threadCountMonitor)
{
_workFlowPool.Add(workerThread, workflowMgr);
_workFlowThreadIDPool.Add(workerThread.ManagedThreadId, workerThread);
workerThread.Start();
++_threadCount;
}
I need to track if a task is completed and I can queue some more work. Also I need to implement TPL for getfile and processfile. What would be the best approach from TPL?
I think your code can be written like below. In this way you don't need to manually queue the work items.