Can I add an attribute to a function to prevent reentry?

前端 未结 9 2326
梦谈多话
梦谈多话 2021-02-15 12:26

At the moment, I have some functions which look like this:

private bool inFunction1 = false;
public void function1()
{
    if (inFunction1) return;
    inFunctio         


        
9条回答
  •  再見小時候
    2021-02-15 13:20

    You may find that you could use PostSharp to accomplish this - along with the suggestions from Anthony about using try/finally. It's likely to be messy though. Also consider whether you want the re-entrancy to be on a per-thread or per-instance basis. (Could multiple threads call into the method to start with, or not?)

    There's nothing like this in the framework itself.

提交回复
热议问题