public IEnumerable <ThreadEntry> GetThreads() { ThreadEntry.Native native = new ThreadEntry.Native(); native.dwSize = (uint)Marshal.SizeOf <ThreadEntry.Native>(); try { bool success = Thread32First(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 = Thread32Next(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 Thread32Next(SafeToolhelp32SnapshotHandle handle, ref ThreadEntry.Native moduleEntry);