Shorten function with bool variable? #5080
Unanswered
doanhquang2005
asked this question in
Q&A
Replies: 1 comment 2 replies
-
That's pretty dangerous. If the method throws an exception, you'll be stuck with This is the usual pattern: private bool isProcessing;
private void Function()
{
if (isProcessing) return;
isProcessing = true;
try
{
// ...
}
finally
{
isProcessing = false;
}
} This can be encapsulated in various ways to avoid repetition of the full pattern. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Ex:

bool IsProcess; void function(){ if(IsProcess) return; IsProcess = true; // TODO IsProcess = false; }
Do we have any shorthand for this case? I have many such commands in my project
Beta Was this translation helpful? Give feedback.
All reactions