Пример #1
0
        private bool IsSelfOrDescendantOf(Process processOfInterest)
        {
            if (SafePredicateTest(() => Equals(processOfInterest)))
            {
                return(true);
            }

            Process[] allProcesses = GetProcesses();

            try
            {
                var     descendantProcesses = new Queue <Process>();
                Process current             = this;

                do
                {
                    foreach (Process candidate in current.GetChildProcesses(allProcesses))
                    {
                        if (SafePredicateTest(() => processOfInterest.Equals(candidate)))
                        {
                            return(true);
                        }

                        descendantProcesses.Enqueue(candidate);
                    }
                } while (descendantProcesses.TryDequeue(out current));
            }
            finally
            {
                foreach (Process process in allProcesses)
                {
                    process.Dispose();
                }
            }

            return(false);
        }