As Miha pointed out, there may be code optimizations that would give you
different results. Some functions could be completely optimized out and may
never appear in a call stack. But the following code should work fine on a
Debug build (with no optimizations)
This is how you get the full stack trace. (Note: The following code is
taken from MSDN - have not tried it myself.)
// Create a StackTrace that captures
// filename, line number and column
// information, for the current thread.
StackTrace st = new StackTrace(true);
for(int i =0; i< st.FrameCount; i++ )
{
// High up the call stack, there is only one stack frame
StackFrame sf = st.GetFrame(i);
Console.WriteLine("\nHigh Up the Call Stack, Method: {0}",
sf.GetMethod() );
}
"Rakesh" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
But when I use the StackFrame.GetMethod().Name property,
this returns the method i am in and not the calling
method...
-----Original Message-----
Lookup StackTrace and StackFrame classes in
System.Diagnostics namespace.
vJ
"Rakehs" <as*@asd.com> wrote in message
news:03****************************@phx.gbl... Hi,
I have a method Show() which is invoked by several
methods at different intervals. I want to identify the
calling method within Show() whenever it is invoked. How do i do this?
Thanks in advance
Rakesh
.