/// <summary>
        /// Populate element with list of properties
        /// </summary>
        /// <param name="element"></param>
        /// <param name="list"></param>
        private static void PopulateWithIndicatedProperties(this A11yElement element, List <int> list)
        {
            element.Clear();
            if (element.IsSafeToRefresh())
            {
                A11yAutomation.GetUIAutomationObject().PollForPotentialSupportedProperties((IUIAutomationElement)element.PlatformObject, out int[] ppids, out string[] ppns);

                // build a cache based on the lists
                var cache = DesktopElementHelper.BuildCacheRequest(list, null);

                // buildupdate cached element
                var uia = ((IUIAutomationElement)element.PlatformObject).BuildUpdatedCache(cache);

                var properties = RetrievePropertiesFromCache(uia, list);

                element.Properties = properties.Where(p => !string.IsNullOrEmpty(p.TextValue)).ToDictionary(d => d.Id);

                element.UpdateGlimpse();

                // release previous UIAElement
                Marshal.ReleaseComObject(uia);
                // release cache interface.
                Marshal.ReleaseComObject(cache);
            }
        }
        /// <summary>
        /// Clone A11yElement for selection
        /// </summary>
        /// <param name="e"></param>
        /// <returns>if element is not live, don't allow clow</returns>
        public static A11yElement CloneForSelection(this A11yElement e)
        {
            try
            {
                if (e != null && e.PlatformObject != null)
                {
                    var cache = DesktopElementHelper.BuildCacheRequest(MiniumProperties, null);

                    var uia = ((IUIAutomationElement)e.PlatformObject).BuildUpdatedCache(cache);
                    Marshal.ReleaseComObject(cache);

                    var ne = new DesktopElement(uia, true, false);
                    ne.PopulateMinimumPropertiesForSelection();

                    return(ne);
                }
            }
            catch (COMException)
            {
            }

            return(null);
        }
        /// <summary>
        /// Refresh the property and patterns with Live data.
        /// it also set the Glimpse
        /// the update is done via caching to improve performance.
        /// </summary>
        /// <param name="useProperties">default is false to refresh it from UIElement directly</param>
        private static void PopulatePropertiesAndPatternsFromCache(this A11yElement element)
        {
            try
            {
                // Get the list of properties to retrieve
                A11yAutomation.GetUIAutomationObject().PollForPotentialSupportedProperties((IUIAutomationElement)element.PlatformObject, out int[] ppids, out string[] ppns);

                var ppl = new List <Tuple <int, string> >();

                for (int i = 0; i < ppids.Length; i++)
                {
                    var id   = (int)ppids.GetValue(i);
                    var name = (string)ppns.GetValue(i);

                    if (DesktopElement.IsExcludedProperty(id, name) == false)
                    {
                        ppl.Add(new Tuple <int, string>(id, name));
                    }
                }

                A11yAutomation.GetUIAutomationObject().PollForPotentialSupportedPatterns((IUIAutomationElement)element.PlatformObject, out int[] ptids, out string[] ptns);
                var ptl = new List <Tuple <int, string> >();

                for (int i = 0; i < ptids.Length; i++)
                {
                    ptl.Add(new Tuple <int, string>((int)ptids.GetValue(i), (string)ptns.GetValue(i)));
                }

                var pplist = (from pp in ppl
                              select pp.Item1).ToList();
                var ptlist = (from pt in ptl
                              select pt.Item1).ToList();

                // build a cache based on the lists
                var cache = DesktopElementHelper.BuildCacheRequest(pplist, ptlist);

                // buildupdate cached element
                var uia = ((IUIAutomationElement)element.PlatformObject).BuildUpdatedCache(cache);

                // retrieve properties from cache
                var ps = (from pp in ppl//.AsParallel()
                          let val = GetPropertyValueFromCache(uia, pp.Item1)
                                    where val != null
                                    select new A11yProperty(pp.Item1, val, pp.Item2));

                element.Properties = ps.Where(p => !string.IsNullOrEmpty(p.TextValue)).ToDictionary(d => d.Id);

                element.UpdateGlimpse();

                // retrieve patterns from cache
                var ptlst = from pt in ptl
                            let pi = A11yPatternFactory.GetPatternInstance(element, uia, pt.Item1, pt.Item2)
                                     where pi != null
                                     select pi;

                element.Patterns = ptlst.ToList();

                // release previous UIAElement
                Marshal.ReleaseComObject(uia);
                // release cache interface.
                Marshal.ReleaseComObject(cache);

                ppl?.Clear();
                ptl?.Clear();
            }
            catch
            {
            }
        }