Ejemplo n.º 1
0
        private Task Wizard(bool FSharpVersion)
        {
            cancelWizard = new CancellationTokenSource();

            // run the study plan wizard in the background on a separate thread (so that the UI remains responsive)
            return(Task.Run(() =>
            {
                if (plan.Items.Count() > 0 && StudyPlannerModel.isLegalPlan(plan.Items))
                {
                    IEnumerable <StudyPlan> wizard;
                    if (FSharpVersion)
                    {
                        wizard = FSharpSchedulingWizard.TryToImproveSchedule(plan.Items);
                    }
                    else
                    {
                        wizard = CSharpSchedulingWizard.TryToImproveSchedule(plan.Items);
                    }

                    foreach (var betterPlan in wizard)
                    {
                        Debug.Assert(StudyPlannerModel.isLegalPlan(plan.Items));
                        uiFactory.StartNew(() =>
                        {
                            // present each progressively improved study plan as they are discovered
                            plan.Clear();
                            plan.AddRange(betterPlan);
                        }, cancelWizard.Token);
                    }
                }
            }, cancelWizard.Token));
        }