Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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;
share|improve this question
3  
Welcome to CodeReview. Does this actually do everything you want it to? CodeReview is a site about improving fully functional code. If you have questions on implementations or want suggestions on unwritten code that would be off-topic. –  Legato Apr 1 at 21:25
2  
Why are you using 'goto' when a while loop seems like it would accomplish the same thing? –  Nick Udell Apr 2 at 10:16
    
I'd recommend that you look at the TPL Dataflow library: msdn.microsoft.com/en-us/library/hh228603%28v=vs.110%29.aspx it looks like there isn't quite enough here to review but I suspect there is some architectural smells right outside of this code. Generally you don't want an infinite loop on your main thread like you appear to have here. –  Bill Barry Apr 2 at 21:25
    
This code is incomplete. What is the type of tskDict? The sources of getFits, WriteProcessingQueue and ReadProcessingQueue methods are important to understand the processing logic. –  almaz 10 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.