public IEnumerable <ProcessEntry> GetProcesses() { ProcessEntry.Native native = new ProcessEntry.Native(); native.dwSize = (uint)Marshal.SizeOf <ProcessEntry.Native>(); try { bool success = Process32FirstW(handle, ref native); if (!success) { throw new Win32Exception(); } } catch (Win32Exception err) when(err.NativeErrorCode == ErrNoMoreFiles) { yield break; } yield return(native.AsManaged()); for (; ;) { try { bool success = Process32NextW(handle, ref native); if (!success) { throw new Win32Exception(); } } catch (Win32Exception err) when(err.NativeErrorCode == ErrNoMoreFiles) { yield break; } yield return(native.AsManaged()); } }
internal static extern bool Process32NextW(SafeToolhelp32SnapshotHandle handle, ref ProcessEntry.Native moduleEntry);