Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print Stack Trace in Output Window

Tags:

c#

debugging

C#, WinForms: Is there a way I can see which methods are calling a specific method? well I can put a break point and see the call stack, but this one is UI related and it is a DoubleClick event, so I thought it will be helpful if something similar to Debug.Writeline(....) can also print call stack on a method so I could write it at the beginning of my method and see ok this time it is cvalled from this method, this time from that method, etc...

like image 200
Bohn Avatar asked Sep 20 '11 14:09

Bohn


2 Answers

Use the Environment.StackTrace property.

like image 164
Roman Starkov Avatar answered Oct 11 '22 16:10

Roman Starkov


What you are looking for is System.Diagnostics.StackTrace. You simply create a new instance at the point where you want to look at the stack.

Beware, though, that creating a stack trace is very expensive.

like image 42
Christian Palmstierna Avatar answered Oct 11 '22 15:10

Christian Palmstierna