System.Diagnostics.NtProcessManager.GetProcessInfos C# (CSharp) Method

GetProcessInfos() static private method

static private GetProcessInfos ( PerformanceCounterLib library ) : System.Diagnostics.ProcessInfo[]
library PerformanceCounterLib
return System.Diagnostics.ProcessInfo[]
        static ProcessInfo[] GetProcessInfos(PerformanceCounterLib library)
        {
            ProcessInfo[] processInfos;

            int retryCount = 5;
            do
            {
                try
                {
                    byte[] dataPtr = library.GetPerformanceData(PerfCounterQueryString);
                    processInfos = GetProcessInfos(library, ProcessPerfCounterId, ThreadPerfCounterId, dataPtr);
                }
                catch (Exception e)
                {
                    throw new InvalidOperationException(SR.CouldntGetProcessInfos, e);
                }

                --retryCount;
            }
            while (processInfos.Length == 0 && retryCount != 0);

            if (processInfos.Length == 0)
                throw new InvalidOperationException(SR.ProcessDisabled);

            return processInfos;
        }

Same methods

NtProcessManager::GetProcessInfos ( PerformanceCounterLib library, int processIndex, int threadIndex, byte data ) : System.Diagnostics.ProcessInfo[]
NtProcessManager::GetProcessInfos ( string machineName, bool isRemoteMachine ) : System.Diagnostics.ProcessInfo[]

Usage Example

        /// <summary>Gets the ProcessInfo for the specified process ID on the specified machine.</summary>
        /// <param name="processId">The process ID.</param>
        /// <param name="machineName">The machine name.</param>
        /// <returns>The ProcessInfo for the process if it could be found; otherwise, null.</returns>
        public static ProcessInfo GetProcessInfo(int processId, string machineName)
        {
            if (IsRemoteMachine(machineName))
            {
                // remote case: we take the hit of looping through all results
                ProcessInfo[] processInfos = NtProcessManager.GetProcessInfos(machineName, isRemoteMachine: true);
                foreach (ProcessInfo processInfo in processInfos)
                {
                    if (processInfo.ProcessId == processId)
                    {
                        return(processInfo);
                    }
                }
            }
            else
            {
                // local case: do not use performance counter and also attempt to get the matching (by pid) process only
                ProcessInfo[] processInfos = NtProcessInfoHelper.GetProcessInfos(pid => pid == processId);
                if (processInfos.Length == 1)
                {
                    return(processInfos[0]);
                }
            }

            return(null);
        }
All Usage Examples Of System.Diagnostics.NtProcessManager::GetProcessInfos