StackTrace.GetFrames 方法

定義

傳回目前堆疊追蹤內的所有堆疊框架的複本。

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()

傳回

StackFrame[]

StackFrame 型別的陣列,表示堆疊追蹤中的函式呼叫。

屬性

範例

下列程式碼範例示範列舉 中的 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

備註

使用傳回的 StackFrame 陣列來列舉和檢查 中的 StackTrace 函式呼叫。 傳回陣列的長度等於 FrameCount 屬性值。

陣列 StackFrame 元素會以反向時間順序排列。 位於 StackFrame 陣列索引 0 的 表示堆疊追蹤中最新的函式呼叫,以及推送至呼叫堆疊的最後一個框架。 at StackFrame 陣列索引 FrameCount 減 1 代表堆疊追蹤中最舊的函式呼叫,以及推送至呼叫堆疊的第一個框架。

GetFrames使用 方法來取得堆疊追蹤中的所有堆疊框架;使用 GetFrame 方法來取得堆疊追蹤中的特定堆疊框架。 索引 StackFrame 的排序方式類似這兩種方法。 例如, StackFrame 在 所 GetFrames 傳回 GetFrame 陣列中索引 0 的 ,相當於 StackFrame 的 ,其輸入索引為 0。

適用於

另請參閱