Get call stack

Source: Internet
Author: User

In C #:

This example shows how to get call stack in. net. Call Stack is representedStacktraceClass and a method call is representedStackframeClass. You can get the frames usingStacktrace. getframesMethod. It returns array of frames. Frame with index 0 is current executing method, frame 1 is calling method, next frame is its caller and so on.

FollowingExample writes call stack method names. It creates an instance of stacktrace (call stack), gets all frames (method CILS) and writes the method names.

[C #]

 
Using system. diagnostics; [stathread] public static void main () {stacktrace = new stacktrace (); // get call stack stackframe [] stackframes =Stacktrace. getframes(); // Get method CILS (frames) // write call stack method names foreach (stackframe in stackframes) {console. writeline (Stackframe. getmethod (). Name); // Write method name }}
 
In Win32:
 
Http://www.codeproject.com/KB/threads/StackWalker.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.