I am trying to use Tasks to do some data processing in parallel. It will be constantly running. It reads from a queue file and if there is data to process the task will start. Once the task stops it will again read the queue file to see if there is other processing to be done. What would be the best way to do this using Tasks?
tskDict.Add("Wf_1", "");
tskDict.Add("Op_1", "");
tskDict.Add("repr_1","");
tskDict.Add("Wf_2", "");
tskDict.Add("Op_2", "");
tskDict.Add("repr_2", "");
Task T1 = new Task(() => getFits(tskDict["Wf_1"], tskDict["Op_1"], false, 1));
Task T2 = new Task(() => getFits(tskDict["Wf_2"], tskDict["Op_2"], false, 2));
restart:
if (T1.Status.Equals(TaskStatus.Running) != true)
{
if (processedT1 != "")
{
WriteProcessingQueue("2", processedT1.Split('_')[0], processedT1.Split('_')[1], false);
processedT1 = string.Empty;
}
if (errorT1 != "")
{
WriteProcessingQueue("3", errorT1.Split('_')[0], errorT1.Split('_')[1], false);
errorT1 = string.Empty;
}
ReadProcessingQueue(1);
if (tskDict["Wa_1"] != "")
{
WriteProcessingQueue("1", tskDict["Wf_1"], tskDict["Op_1"], false);
T1.Start();
}
}
if (T2.Status.Equals(TaskStatus.Running) != true)
{
if (processedT2 != "")
{
WriteProcessingQueue("2", processedT2.Split('_')[0], processedT2.Split('_')[1], false);
processedT2 = string.Empty;
}
if (errorT2 != "")
{
WriteProcessingQueue("3", errorT2.Split('_')[0], errorT2.Split('_')[1], false);
errorT2 = string.Empty;
}
ReadProcessingQueue(2);
if (tskDict["Wf_2"] != "")
{
WriteProcessingQueue("1", tskDict["Wf_2"], tskDict["Op_2"], false);
T2.Start();
}
}
goto restart;
tskDict
? The sources ofgetFits
,WriteProcessingQueue
andReadProcessingQueue
methods are important to understand the processing logic. – almaz 10 hours ago