C#使用StackTrace获取方法被谁调用
2014-08-27 11:57
573 查看
在方法中扔进这段
然后就能在output窗口(Alt+2)看到类似
再高(dan)级(teng)一点 ,写个公用的静态方法,并用上“DEBUG”条件之,然后……在需要的地方调用之
思考题:能否利用扩展方法扩展到Debug命名空间下呢?
另:西加加得到调用堆栈的东东都在execinfo.h 点击乘坐直达列车
System.Diagnostics.Debug.WriteLine(new string('*', 78)); System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(); System.Diagnostics.StackFrame[] sfs = st.GetFrames(); for (int u = 0; u < sfs.Length; ++u) { System.Reflection.MethodBase mb = sfs[u].GetMethod(); System.Diagnostics.Debug.WriteLine("[CALL STACK][{0}]: {1}.{2}", u, mb.DeclaringType.FullName, mb.Name); }
然后就能在output窗口(Alt+2)看到类似
****************************************************************************** [CALL STACK][0]: WindowsFormsApplication1.Form1.button1_Click [CALL STACK][1]: System.Windows.Forms.Button.OnMouseUp [CALL STACK][2]: System.Windows.Forms.Control.WmMouseUp [CALL STACK][3]: System.Windows.Forms.Control.WndProc [CALL STACK][4]: System.Windows.Forms.ButtonBase.WndProc [CALL STACK][5]: System.Windows.Forms.Button.WndProc [CALL STACK][6]: System.Windows.Forms.NativeWindow.DebuggableCallback [CALL STACK][7]: System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW [CALL STACK][8]: System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW [CALL STACK][9]: System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop [CALL STACK][10]: System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner [CALL STACK][11]: System.Windows.Forms.Application+ThreadContext.RunMessageLoop [CALL STACK][12]: WindowsFormsApplication1.Program.Main [CALL STACK][13]: System.AppDomain._nExecuteAssembly [CALL STACK][14]: Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly [CALL STACK][15]: System.Threading.ExecutionContext.RunInternal [CALL STACK][16]: System.Threading.ExecutionContext.Run [CALL STACK][17]: System.Threading.ExecutionContext.Run [CALL STACK][18]: System.Threading.ThreadHelper.ThreadStart
再高(dan)级(teng)一点 ,写个公用的静态方法,并用上“DEBUG”条件之,然后……在需要的地方调用之
[System.Diagnostics.Conditional("DEBUG")] static public void OutputCallStack() { System.Diagnostics.Debug.WriteLine(new string('*', 78)); System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(); System.Diagnostics.StackFrame[] sfs = st.GetFrames(); for (int u = 1; u < sfs.Length; ++u) { System.Reflection.MethodBase mb = sfs[u].GetMethod(); System.Diagnostics.Debug.WriteLine("[CALL STACK][{0}]: {1}.{2}", u, mb.DeclaringType.FullName, mb.Name); } }
思考题:能否利用扩展方法扩展到Debug命名空间下呢?
另:西加加得到调用堆栈的东东都在execinfo.h 点击乘坐直达列车
相关文章推荐
- C#使用StackTrace获取方法被谁调用
- 在C#中获取IronPthon2.7异常时的调用方法堆栈,调试使用。
- c#中使用call调用oracle存储过程并获取out参数值
- 使用C#调用外部Ping命令获取网络连接情况
- 使用C#调用外部Ping命令获取网络连接情况
- 使用C#调用外部Ping命令获取网络连接情况
- 使用IDispatch::Invoke函数在C++中调用C#实现的托管类库方法
- 使用C#调用外部Ping命令获取网络连接情况
- 使用C#调用外部Ping命令获取网络连接情况
- 利用sender的Parent获取GridView中的当前行 不用AJAX实现前台JS调用后台C#方法(小技巧) AjaxControlToolkit的CalendarExtender的本地化
- 使用C#调用外部Ping命令获取网络连接情况
- 使用IDispatch::Invoke函数在C++中调用C#实现的托管类库方法
- 使用C#调用外部Ping命令获取网络连接情况
- 使用C#调用外部Ping命令获取网络连接情况[转载CSDN]
- 使用C#调用外部Ping命令获取网络连接情况
- 使用C#调用外部Ping命令获取网络连接情况
- 使用C#调用外部Ping命令获取网络连接情况
- 使用C#调用外部Ping命令获取网络连接情况
- 转:使用IDispatch::Invoke函数在C++中调用C#实现的托管类库方法
- 使用IDispatch::Invoke函数在C++中调用C#实现的托管类库方法