예제 #1
0
        public static ThreadEntry[] GetThreads(uint processId)
        {
            var handle = NativeMethods.CreateToolhelp32Snapshot(CreateToolhelp32Flags.SNAPTHREAD, processId);

            if ((int)handle <= 0)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            var list = new List <ThreadEntry>();

            var te    = new byte[SIZE];
            var bytes = BitConverter.GetBytes(SIZE);

            Buffer.BlockCopy(bytes, 0, te, SIZE_OFFSET, bytes.Length);

            for (var i = NativeMethods.Thread32First(handle, te); i == 1; i = NativeMethods.Thread32Next(handle, te))
            {
                var entry = new ThreadEntry(te);
                if ((processId == 0) || (entry.OwnerProcessId == processId))
                {
                    list.Add(entry);
                }
            }

            NativeMethods.CloseToolhelp32Snapshot(handle);

            return(list.ToArray());
        }
예제 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public ThreadEntry[] GetThreads()
 {
     return(ThreadEntry.GetThreads(ProcessId));
 }