5
Views
1
Comments
Get Calling Action or Timer
Question
Is it possible to get information of the Calling action name  or in which Timer my action is running?

something like this in C#

https://www.csharp-examples.net/reflection-calling-method-name/

Kind regards,
Matthias
2012-10-08 11-59-27
Guilherme Pereira
Staff
Hi Mathias,

I did a quick test and its indeed possible. You could crerate an extension with an action that returns the method name.
I've done a sample that returns the entire stack (separated with new lines)

 public void MssGetMethodName(out string ssMethodName) {

        StackTrace stackTrace = new StackTrace();

 

   ssMethodName = "";

 

   for (int i = 0; i < stackTrace.FrameCount; i++)

   {

         ssMethodName += string.Format("{0} : {1} : {2}", i,                                                    stackTrace.GetFrame(i).GetMethod().Name, Environment.NewLine);

          }

 

} // MssGetMethodName

and this was the output



I also tested inside a timer and the name of the action came on index 3 so I would say for you to see which one fits your goal.

Hope this helps.

Cheers,
LGP
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.