コード例 #1
0
        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());
            }
        }
コード例 #2
0
 internal static extern bool Thread32Next(SafeToolhelp32SnapshotHandle handle, ref ThreadEntry.Native moduleEntry);