Пример #1
0
        internal static List <TheThreadInfo> GetThreadInfo()
        {
            List <TheThreadInfo> tList = new List <TheThreadInfo>();

#if CDE_STANDARD //No Thread Name Diagnostics
#else
            try
            {
                int cid = NativeMethods.GetCurrentThreadId();
                foreach (ProcessThread pt in Process.GetCurrentProcess().Threads)
                {
                    TheThreadInfo t = new TheThreadInfo()
                    {
                        Priority = PriorityToString(pt.CurrentPriority),
                        ID       = pt.Id
                    };
                    if (t.ID < MAX_IDS)
                    {
                        t.Name = MyThreadNames[t.ID];
                        //t.StackFrame = MyThreadStacks[t.ID];
                        if (t.ID == cid)
                        {
                            t.Name = "GETTHREADINFO";
                        }
                        else
                        {
                            if (MyThreadStacks[t.ID] != null)
                            {
                                t.IsBackground = MyThreadStacks[t.ID].IsBackground;
                                t.IsPooled     = MyThreadStacks[t.ID].IsThreadPoolThread;
#pragma warning disable CS0618 // System.Diagnostics.StrackTrace requires the thread to be suspended
                                MyThreadStacks[t.ID].Suspend();
                                t.StackFrame = TheCommonUtils.GetStackInfo(new System.Diagnostics.StackTrace(MyThreadStacks[t.ID], true));
                                MyThreadStacks[t.ID].Resume();
#pragma warning restore CS0618
                            }
                        }
                    }
                    t.CoreTimeInMs = pt.PrivilegedProcessorTime.TotalMilliseconds;
                    t.State        = ThreadStateToString(pt.ThreadState);
                    t.UserTimeInMs = pt.UserProcessorTime.TotalMilliseconds;
                    if (ThreadState.Wait != pt.ThreadState)
                    {
                        t.WaitReason = "Not Waiting";
                    }
                    else
                    {
                        t.WaitReason = ThreadWaitReasonToString(pt.WaitReason);
                    }
                    t.StartTime = pt.StartTime;
                    tList.Add(t);
                }
            }
            catch (Exception e)
            {
                TheBaseAssets.MySYSLOG.WriteToLog(999, new TSM("Diagnostics", "Thread Diagnostics Failed", eMsgLevel.l1_Error, e.ToString()));
            }
#endif
            return(tList);
        }