Home
Manage Your Code
Snippet: How to access the Call Stack C# (C#)
Title: How to access the Call Stack C# Language: C#
Description: Access the call stack window content Views: 97
Author: rohan rohan Date Added: 7/28/2008
Copy Code  
1view plaincopy to clipboardprint?
2// First create an instance of the call stack   
3StackTrace callStack = new StackTrace();   
4  
5// Next select the frame we want...   
6// 0 : current frame for the current method   
7// 1 : Frame that called the current method   
8// 2 : Frame that called the frame that called the current method   
9// 3 : ...you get the idea!   
10StackFrame frame = callStack.GetFrame(1);   
11  
12// Using StackFrame.GetMethod(), which returns a    
13// MethodBase object, we can obtain detailed    
14// information about about a method   
15MethodBase method = frame.GetMethod();   
16  
17// Get the declaring type and method names    
18string declaringType = method.DeclaringType.Name;   
19string methodName = method.Name;  
20
21source : http://neilkilbride.blogspot.com/2008/04/how-to-access-call-stack-c.html