/// <summary>
        /// Refresh tree node data with all children at once.
        /// <param name="mode">indicate the mode</param>
        /// </summary>
        public void RefreshTreeData(TreeViewMode mode)
        {
            this.WalkerMode = mode;
            if (this.Elements.Count != 0)
            {
                this.Elements.Clear();
            }

            //Set parent of Root explicitly for testing.
            var ancestry = new DesktopElementAncestry(this.WalkerMode, this.SelectedElement);

            // Pre-count the ancestors in our bounded count, so that our count is accurate
            _elementCounter.TryAdd(ancestry.Items.Count);

            this.TopMostElement = ancestry.First;

            // clear children
            ListHelper.DisposeAllItemsAndClearList(this.SelectedElement.Children);
            this.SelectedElement.UniqueId = 0;

            PopulateChildrenTreeNode(this.SelectedElement, ancestry.Last, ancestry.NextId);

            // do population of ancesters all togather with children
            var list = new List <A11yElement>(this.Elements);

            foreach (var item in ancestry.Items)
            {
                this.Elements.Add(item);
            }

            // populate Elements first
            this.Elements.AsParallel().ForAll(e => e.PopulateAllPropertiesWithLiveData());

            // check whether there is any elements which couldn't be updated in parallel, if so, update it in sequence.
            var nuel = this.Elements.Where(e => e.Properties == null);

            if (nuel.Any())
            {
                nuel.ToList().ForEach(e => e.PopulateAllPropertiesWithLiveData());
            }

            // run tests
            list.AsParallel().ForAll(e =>
            {
                e.ScanResults?.Items.Clear();
                RuleRunner.Run(e);
            });
        }
        /// <summary>
        /// Refresh tree node data with all children at once.
        /// </summary>
        /// <param name="e"></param>
        /// <param name="mode"></param>
        /// <param name="showAncestry"></param>
        public void GetTreeHierarchy(A11yElement e, TreeViewMode mode)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            var begin = DateTime.Now;

            this.WalkerMode = mode;

            //Set parent of Root explicitly for testing.
            A11yElement parent   = null;
            var         ancestry = new DesktopElementAncestry(this.WalkerMode, e);

            parent = ancestry.Last;

            this.RootElement = ancestry.First;

            // clear children
            ListHelper.DisposeAllItemsAndClearList(e.Children);

            // populate selected element relationship and add it to list.
            e.Parent         = ancestry.Last;
            e.TreeWalkerMode = this.WalkerMode; // set tree walker mode.
            e.UniqueId       = 0;               // it is the selected element which should be id 0.
            this.Elements.Add(e);

            PopulateChildrenTreeNode(e, ancestry.NextId);

            // populate decendent Elements first in parallel
            this.Elements.AsParallel().ForAll(el =>
            {
                el.PopulateMinimumPropertiesForSelection();
            });

            // Add ancestry into Elements list.
            foreach (var item in ancestry.Items)
            {
                this.Elements.Add(item);
            }

            this.LastWalkTime = DateTime.Now - begin;
        }
        /// <summary>
        /// Refresh tree node data with all children at once.
        /// </summary>
        /// <param name="e"></param>
        /// <param name="mode"></param>
        /// <param name="showAncestry"></param>
        public void GetTreeHierarchy(A11yElement e, TreeViewMode mode)
        {
            var begin = DateTime.Now;

            this.WalkerMode = mode;

            //Set parent of Root explicitly for testing.
            A11yElement parent   = null;
            var         ancestry = new DesktopElementAncestry(this.WalkerMode, e);

            parent = ancestry.Last;

            this.RootElement = ancestry.First;

            // clear children
            e.Children?.ForEach(c => c.Dispose());
            e.Children?.Clear();

            // populate selected element relationship and add it to list.
            e.Parent         = ancestry.Last;
            e.TreeWalkerMode = this.WalkerMode; // set tree walker mode.
            e.UniqueId       = 0;               // it is the selected element which should be id 0.
            this.Elements.Add(e);

            PopulateChildrenTreeNode(e, ancestry.NextId);

            // populate decendent Elements first in parallel
            this.Elements.AsParallel().ForAll(el =>
            {
                el.PopulateMinimumPropertiesForSelection();
            });

            // Add ancestry into Elements list.
            this.Elements.AddRange(ancestry.Items);

            this.LastWalkTime = DateTime.Now - begin;
        }