Пример #1
0
        /// <summary>
        /// Enumerates all processes that belong to that job
        /// </summary>
        /// <returns>A process enumerator for the job</returns>
        public IEnumerator <Process> GetEnumerator()
        {
            CheckDisposed();

            bool done = false;
            var  ids  = new JobBasicProcessIDs {
                ListSize = 8,
            };

            do
            {
                int resultBytes;


                ids.Identifiers = new int[ids.ListSize];
                if (!QueryProcessIDs(Handle, JobInfoClass.ProcessIDs, ref ids,
                                     JobBasicProcessIDs.Size, out resultBytes))
                {
                    throw new Win32Exception();
                }

                done = ids.ListSize <= ids.RealCount;
                if (!done)
                {
                    ids.ListSize *= 2;
                }
            } while (!done);

            return(ids.Identifiers.Take(ids.RealCount)
                   .Select(Process.GetProcessById).GetEnumerator());
        }
Пример #2
0
 static extern bool QueryProcessIDs(IntPtr job, JobInfoClass infoClass, ref JobBasicProcessIDs info,
                                    int infoBytes, out int resultBytes);