14

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

2
  • Instead of printing debug messages, you could just put your cursor on the method name and press Shift+F12 (Edit.FindAllReferences)... Commented Sep 20, 2011 at 14:12
  • 3
    yes but it does not mean all of those methods are calling my method in that specific execution path. Envirnoment.StrackTrace answer is correct. Commented Sep 20, 2011 at 14:14

2 Answers 2

24

Use the Environment.StackTrace property.

Sign up to request clarification or add additional context in comments.

Comments

4

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.