How do I get a unique instance identifier of method's parent method? RRS feed

  • Question

  • Hi,

    I have tried a lot of ways to get a unique identifier of a method's parent method.

    I can get information about the parent method using Reflection but If I executed the method 2 times or asynchronously, i get the same properties that I would use to build the identifier (HashCode, Token and etc). I have already tried all the properties and methods and searched on google a lot about it but I didn't find any solution.

    I want to do that to build my custom transaction scope but i can make this work.

    Thank you.

    Wednesday, October 5, 2011 7:44 PM


  • What do you mean by parent method? Methods can't be nested in C# (ignoring anonymous methods for the moment), so there is no parent/child structure. If you mean you want to get the calling method, you can get it using the StackTrace class (in particular, the GetFrames() method).

    In any case, there is no way to tell one instance of a method call from another. As far as the program is concerned, it's all the same method which just gets called multiple times. I don't know if any sort of "instance identifier" or anything which is exposed through reflection.

    Check out My Blog for tech news, development tips, and other information for geeks like me.
    • Marked as answer by Paul Zhou Thursday, October 13, 2011 3:02 AM
    Wednesday, October 5, 2011 8:50 PM