コード例 #1
0
        private void ExecuteJobs_MaximizeJobsInParallel()
        {
            this.DivideStepsIntoGroups();

            StepGroup currentStepGroup      = null;
            Processor currentProcessor      = null;
            bool      resultCheckingPending = false;
            bool      allIsDone             = false;

            while (allIsDone == false)
            {
                if (this.MainContext.ParentFinished == true)
                {
                    return;
                }

                allIsDone        = true;
                currentStepGroup = null;
                currentProcessor = null;

                foreach (StepGroup stepGroup in this.StepGroupList)
                {
                    if (stepGroup.AllStepsExecuted == false)
                    {
                        allIsDone = false;

                        if (stepGroup.Processor == null)
                        {
                            currentStepGroup = stepGroup;
                            break;
                        }
                    }
                }

                if (allIsDone == false)
                {
                    if (currentStepGroup == null)
                    {
                        Thread.Sleep(Processor.WAIT_TIME_IN_MILLISECONDS);
                    }
                    else
                    {
                        foreach (Processor processor in this.ProcessorList)
                        {
                            if (processor.IsIdle == true)
                            {
                                currentProcessor = processor;
                                break;
                            }
                        }

                        if (currentProcessor != null)
                        {
                            if (currentProcessor.CurrentStepGroup != null)
                            {
                                currentProcessor.OnLongOperationCompleted();
                            }

                            currentProcessor.RunStepGroupAsync(currentStepGroup);
                            resultCheckingPending = true;
                        }
                        else
                        {
                            Thread.Sleep(Processor.WAIT_TIME_IN_MILLISECONDS);
                        }
                    }
                }

                foreach (StepGroup stepGroup in this.StepGroupList)
                {
                    if (stepGroup.Processor != null && stepGroup.Processor.IsIdle == true)
                    {
                        stepGroup.Processor.OnLongOperationCompleted();
                    }
                }
            }

            while (resultCheckingPending == true)
            {
                if (this.MainContext.ParentFinished == true)
                {
                    return;
                }

                resultCheckingPending = false;
                currentProcessor      = null;

                foreach (Processor processor in this.ProcessorList)
                {
                    if (processor.IsIdle == false)
                    {
                        resultCheckingPending = true;
                    }
                    else
                    {
                        if (processor.CurrentStepGroup != null)
                        {
                            processor.OnLongOperationCompleted();
                            currentProcessor = processor;
                        }
                    }
                }

                if (currentProcessor == null && resultCheckingPending == true)
                {
                    Thread.Sleep(Processor.WAIT_TIME_IN_MILLISECONDS);
                }
            }
        }