Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8993073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:06:45+00:00 2026-06-15T23:06:45+00:00

I want to prohibit reentrancy for large set of methods. for the single method

  • 0

I want to prohibit reentrancy for large set of methods.

for the single method works this code:

bool _isInMyMethod;
void MyMethod()
{
    if (_isInMethod)
        throw new ReentrancyException();

    _isInMethod = true;
    try
    {
        ...do something...
    }
    finally
    {
        _isInMethod = false;
    }
}

This is tedious to do it for every method.
So I’ve used StackTrace class:

        public static void ThrowIfReentrant()
        {
            var stackTrace = new StackTrace(false);
            var frames = stackTrace.GetFrames();
            var callingMethod = frames[1].GetMethod();
            if (frames.Skip(2).Any( frame => EqualityComparer<MethodBase>.Default.Equals(callingMethod,frame.GetMethod())))
                throw new ReentrancyException();
        }

It works fine but looks more like a hack.

Does .NET Framework have special API to detect reentrancy?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:06:46+00:00Added an answer on June 15, 2026 at 11:06 pm

    I recommend using PostSharp to solve your problem. Although it might be expensive to use commercial tool only for a specific reason I suggest you take a look since this tool can solve other problems better suited to be solved by AOP (logging, transaction management, security and more). The company web site is here and you can take a look on examples here. Pluralsight has a good course on the AOP methodology with examples in PostSharp here. Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Want to verify that my understanding of how this works. Have a C++ Class
Want to trigger itemClicked event for a QTreeWidget Item using the following code. connect(aTreeWidget,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(CallM(QTreeWidgetItem*
Want to code a key pad for an calculator. What I want to make
My base controller has this override: protected override void OnException(ExceptionContext filterContext) { // http://forums.asp.net/t/1318736.aspx
Want to show UIButton done on UIScrollView for images. With the below code UIButton
I'm looking for a following pattern: I have several methods like this: 1. private
Want to mimic php code in c# . I want to Capture raw image
For my game using GLFW for windowing, I want to prohibit the user from
want to query below xml <courseList filedUnder=Courses> <category code=4wd title=4wd Operation> <product code=lr title=4wd
I have a project with autotools: automake, autoconf. I want to prohibit make from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.