C# Visual Studio。使用stacktrace的序列作为命中断点条件

C# Visual Studio。使用stacktrace的序列作为命中断点条件,c#,.net,visual-studio,visual-studio-2013,C#,.net,Visual Studio,Visual Studio 2013,我使用了命中断点条件 (new System.Diagnostics.StackTrace(true).GetFrame(2) != null && new System.Diagnostics.StackTrace(true).GetFrame(2).GetMethod().Name == "UpdateFromLocationInfo") 当我一步一步地点击这个断点时,我通过快速观察检查了这个条件,结果是真的。但是条件在f5模式下不起作用如果您试图使用条件表达式在当前方

我使用了命中断点条件

(new System.Diagnostics.StackTrace(true).GetFrame(2) != null 
&& new System.Diagnostics.StackTrace(true).GetFrame(2).GetMethod().Name 
== "UpdateFromLocationInfo")

当我一步一步地点击这个断点时,我通过快速观察检查了这个条件,结果是真的。但是条件在f5模式下不起作用

如果您试图使用条件表达式在当前方法中放置条件断点,则当前方法应为“UpdateFromLocationInfo”。StackTrace上的new始终适用于新建对象所在的当前方法

        // Create a StackTrace that captures filename, line number, and column 
        // information for the current thread.
            StackTrace st = new StackTrace(true);
            StackFrame[] stFrames = st.GetFrames();

            foreach (StackFrame sf in stFrames)
            {
                Console.WriteLine(sf.GetMethod());
            }
          //The StackFrame at array index 0 represents the most recent function call 
          // in the stack trace and the last 
          //frame pushed onto the call stack.
            if ((new StackTrace(true).GetFrame(0) != null && 
            new  StackTrace(true).GetFrame(0).GetMethod().Name == "UpdateFromLocationInfo"))
            {
            }
            else
            {
            }

通过上述过程,您可以清楚地看到输出。

作为一种解决方法,您可以将其放入if语句中,然后在if语句中放入一个非条件断点。显然,在完成调试后,您会希望恢复这一点,我不需要使用其他代码。我只想使用VisualStudioInstrument:右键单击断点,然后选择条件。。。我明白了。我告诉你一个解决办法,如果你不能让它以你尝试的方式工作it@BenAaronson谢谢但这不适合我的情况