ADVERTISEMENT
ADVERTISEMENT

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

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 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 »

ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.