Επεξεργασία

Κοινή χρήση μέσω


StackTrace.GetFrames Method

Definition

Returns a copy of all stack frames in the current stack trace.

public:
 cli::array <System::Diagnostics::StackFrame ^> ^ GetFrames();
public:
 virtual cli::array <System::Diagnostics::StackFrame ^> ^ GetFrames();
public System.Diagnostics.StackFrame[] GetFrames ();
public virtual System.Diagnostics.StackFrame[] GetFrames ();
public virtual System.Diagnostics.StackFrame?[] GetFrames ();
[System.Runtime.InteropServices.ComVisible(false)]
public virtual System.Diagnostics.StackFrame[] GetFrames ();
member this.GetFrames : unit -> System.Diagnostics.StackFrame[]
abstract member GetFrames : unit -> System.Diagnostics.StackFrame[]
override this.GetFrames : unit -> System.Diagnostics.StackFrame[]
[<System.Runtime.InteropServices.ComVisible(false)>]
abstract member GetFrames : unit -> System.Diagnostics.StackFrame[]
override this.GetFrames : unit -> System.Diagnostics.StackFrame[]
Public Function GetFrames () As StackFrame()
Public Overridable Function GetFrames () As StackFrame()

Returns

An array of type StackFrame representing the function calls in the stack trace.

Attributes

Examples

The following code example demonstrates enumerating the frames in a StackTrace.

StackTrace^ st = gcnew StackTrace( 1,true );
array<StackFrame^>^stFrames = st->GetFrames();
for ( int i; i < stFrames->Length; i++ )
{
   StackFrame^ sf = stFrames[ i ];
   Console::WriteLine( "Method: {0}", sf->GetMethod() );

}
StackTrace st = new StackTrace(1, true);
StackFrame [] stFrames = st.GetFrames();

foreach(StackFrame sf in stFrames )
{
   Console.WriteLine("Method: {0}", sf.GetMethod() );
}
Dim strace As New StackTrace(1, True)
Dim stFrames As StackFrame() = strace.GetFrames()

Dim sf As StackFrame
For Each sf In  stFrames
   Console.WriteLine("Method: {0}", sf.GetMethod())
Next sf

Remarks

Use the returned StackFrame array to enumerate and examine function calls in the StackTrace. The length of the returned array is equal to the FrameCount property value.

The StackFrame array elements are in reverse chronological order. 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. The StackFrame at array index FrameCount minus 1 represents the oldest function call in the stack trace and the first frame pushed onto the call stack.

Use the GetFrames method to obtain all stack frames in a stack trace; use the GetFrame method to obtain a specific stack frame in a stack trace. The StackFrame indexes are ordered alike by the two methods. For example, the StackFrame at index 0 in the array returned by GetFrames is equivalent to the StackFrame returned by GetFrame with an input index of 0.

Applies to

See also