Exemple #1
0
        private async void WalkNodes(TreeNodeCollection nodes)
        {
            foreach (TreeNode treeNode in nodes)
            {
                if (treeNode.Checked && treeNode.Tag != null)
                {
                    string tag = treeNode.Tag.ToString();

                    // Create treatment instance based on checkbox tag
                    string     typeStr       = "Chemo.Treatment." + tag;
                    Type       componentType = Type.GetType(typeStr);
                    ITreatment tr            = (ITreatment)Activator.CreateInstance(componentType);

                    // Perform treatment work in the background to not lock up the UI
                    // Only run one task at a time because funny things happen when they run in parallel
                    logger.Log("=== Applying: {0} ===", treeNode.Text);
                    await Task.Run(() =>
                                   tr.PerformTreatment()
                                   );

                    logger.Log("");
                }

                WalkNodes(treeNode.Nodes);
            }
        }