// Assuming this uses calls from multiple threads, I used volatile.
volatile bool executed = false;
object lockExcecuted = new object();
void DoSomething()
{
lock (lockExecuted)
{
if (executed) return;
executed = true;
}
// do something
}
Run Code Online (Sandbox Code Playgroud)