VB.Net program to get all stack frames using StackTrace class

Here, we are going to learn how to get all stack frames using StackTrace class in VB.Net?
Submitted by Nidhi, on January 18, 2021 [Last updated : March 08, 2023]

Getting all stack frames in VB.Net

Here, we will use StackTrace class which is available in the "System. Diagnostics" namespace, and print the stack frames on the console screen.

Program/Source Code:

The source code to get all stack frames using StackTrace class is given below. The given program is compiled and executed successfully.

VB.Net code to get all stack frames using StackTrace class

'VB.Net program to get all stack frames using 
'StackTrace class.

Imports System
Imports System.Diagnostics

Module Module1
    Sub Main()
        Dim trace As New StackTrace()
        Dim frames() As StackFrame

        frames = trace.GetFrames()

        Console.WriteLine("Frames: ")
        For Each frame As StackFrame In frames
            Console.WriteLine(vbTab & "Method Name: " & frame.GetMethod().Name)
            Console.WriteLine(vbTab & "Module Name: {0}", frame.GetMethod().Module)
            Console.WriteLine()
        Next
    End Sub
End Module

Output

Frames:
        Method Name: Main
        Module Name: ConsoleApplication2.exe

Press any key to continue . . .

Explanation

In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program, And, we created an object of StackTrace class and then get frames using GetFrames() method of StackTrace class. After that print the method name and module name using the "For Each" loop on the console screen.

VB.Net Data Structure Programs »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.