Exemple #1
0
        /// <summary>
        /// Attempts to find a process by enumerating all processes and filtering through them with
        /// the given callback.
        /// </summary>
        /// <param name="callback">
        /// Takes in a process and returns true if the process should be returned in the filtered
        /// list of processes.
        /// </param>
        public List <IProcess> FindProcess(Func <IProcess, bool> callback)
        {
            var result = new List <IProcess>();

            foreach (var process in processProxy.GetProcesses())
            {
                try {
                    if (callback(process))
                    {
                        result.Add(process);
                    }
                } catch {
                    //Native exceptions are caught here
                    //Such as Win32Exceptions thrown if we try to look into a 32-bit process
                }
            }
            return(result);
        }