You need a view of what the stack looks like at any particular point in your application. However, you do not have an exception object from which to obtain this stack trace.
Use the following line of code to obtain a stack trace at any point in your application:
string currentStackTrace = System.Environment.StackTrace;
currentStackTrace now contains the
stack trace at the location where this line of code was executed.
A good use of the Solution is tracking down stack overflow problems. You can obtain the current stack trace at various points in your application and then calculate the stack depth. This depth calculation can then be logged to determine when and why the stack is overflowing or potential trouble spots where the stack may grow very large.
It is very easy to
obtain a stack trace using the
Unfortunately, this stack trace also lists three methods defined in
System.Environment class that are called when
you use the
Environment.StackTrace property. The
returned stack trace, using this method, will look something like the
at System.Environment.GetStackTrace(Exception e) at System.Environment.GetStackTrace(Exception e) at System.Environment.get_StackTrace( ) at Chapter_Code.Class1.ObtainingStackTrace( ) in c:\book cs cookbook\test.cs:line 260 at Chapter_Code.Class1.Main(String args) in c:\book cs cookbook\main.cs:line 78
The first three items in the stack ...