当前位置: 首页>>代码示例>>C#>>正文


C# IDebugThread2.GetThreadId方法代码示例

本文整理汇总了C#中IDebugThread2.GetThreadId方法的典型用法代码示例。如果您正苦于以下问题:C# IDebugThread2.GetThreadId方法的具体用法?C# IDebugThread2.GetThreadId怎么用?C# IDebugThread2.GetThreadId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDebugThread2的用法示例。


在下文中一共展示了IDebugThread2.GetThreadId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PrintFrames

        public static ExceptionStackInformation PrintFrames(IDebugThread2 pThread)
        {
            int hr = 0;
            uint threadID = 0;
            ExceptionStackInformation exceptionStackInfo = null;
            hr = pThread.GetThreadId(out threadID);

            IEnumDebugFrameInfo2 enumDebugFrameInfo2;
            hr = pThread.EnumFrameInfo(enum_FRAMEINFO_FLAGS.FIF_FRAME, 0, out enumDebugFrameInfo2);
            if (hr == 0)
            {
                FRAMEINFO[] frameInfo = new FRAMEINFO[1];
                uint fetched = 0;
                hr = enumDebugFrameInfo2.Reset();

                exceptionStackInfo = new ExceptionStackInformation();

                while (enumDebugFrameInfo2.Next(1, frameInfo, ref fetched) == VSConstants.S_OK)
                {
                    IDebugStackFrame3 stackFrame = frameInfo[0].m_pFrame as IDebugStackFrame3;

                    //IDebugThread2 debugThread;
                    IDebugThread2 debugThread;
                    hr = stackFrame.GetThread(out debugThread);

                    uint sfThreadID = 0;
                    hr = debugThread.GetThreadId(out sfThreadID);

                    if (sfThreadID == threadID)
                    {
                        System.Diagnostics.Debug.WriteLine("We got the right stackframe!!!");
                        if (stackFrame != null)
                        {
                            StackFrameInformation stackFrameInfo = new StackFrameInformation();

                            IDebugDocumentContext2 docContext;
                            hr = stackFrame.GetDocumentContext(out docContext);
                            TEXT_POSITION[] startPos = new TEXT_POSITION[1];
                            TEXT_POSITION[] endPos = new TEXT_POSITION[1];
                            if (docContext == null)
                                continue;
                            hr = docContext.GetStatementRange(startPos, endPos);

                            var advancedThread = pThread as IDebugThread3;
                            if (advancedThread != null && advancedThread.IsCurrentException() == 0)
                            {
                                var message = ExtractExceptionMessage(stackFrame);
                                if (message != null)
                                {
                                    System.Diagnostics.Debug.WriteLine("EXCEPTION: " + message);
                                    exceptionStackInfo.ExceptionMessage = message;
                                }

                                var type = ExtractExceptionType(stackFrame);
                                if (type != null)
                                {
                                    System.Diagnostics.Debug.WriteLine("EXCEPTION TYPE: " + type);
                                    type = type.Replace("\"", "");
                                    exceptionStackInfo.ExceptionKind = type;
                                }
                            }

                            // not for cs...debugging js
                            //IDebugDocument2 document;
                            //docContext.GetDocument(out document);
                            //IDebugDocumentText2 documentText = document as IDebugDocumentText2;
                            //var line = GetDocumentText(documentText, startPos[0]);
                            var line = GetTextLine(docContext, startPos[0], endPos[0]);
                            System.Diagnostics.Debug.WriteLine(string.Format("Line {0}", line ));

                            string fileName = "";
                            stackFrame.GetName(out fileName);

                            System.Diagnostics.Debug.WriteLine(string.Format("File {0} Function {1}", fileName, frameInfo[0].m_bstrFuncName));

                            string t = string.Format("start: line({0}) col({1})", startPos[0].dwLine.ToString(), startPos[0].dwColumn.ToString());
                            System.Diagnostics.Debug.WriteLine(t);
                            t = string.Format("end: line({0}) col({1})", endPos[0].dwLine.ToString(), endPos[0].dwColumn.ToString());
                            System.Diagnostics.Debug.WriteLine(t);

                            stackFrameInfo.File = fileName;
                            stackFrameInfo.LineNumber = (int)startPos[0].dwLine;
                            stackFrameInfo.ColumnNumber = (int)startPos[0].dwColumn;
                            stackFrameInfo.FramePath = frameInfo[0].m_bstrFuncName;
                            stackFrameInfo.Line = line;
                            exceptionStackInfo.Frames.Add(stackFrameInfo);
                        }
                    }
                }
            }

            return exceptionStackInfo;
        }
开发者ID:chrisparnin,项目名称:ganji,代码行数:93,代码来源:HandleException.cs


注:本文中的IDebugThread2.GetThreadId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。