Method RunOnce
RunOnce(ref bool, Action, bool)
Executes the specified action only once, ensuring it is not run again if already executed.
public static void RunOnce(ref bool alreadyExecuted, Action action, bool useTimer = true)
Parameters
alreadyExecutedboolA reference to a Boolean value indicating whether the action has already been executed. Set to true after the action is run.
actionActionThe action to execute if it has not already been executed. Cannot be null.
useTimerbooltrue to execute the action asynchronously using a timer; otherwise, false to execute the action immediately.
Remarks
If useTimer is set to true, the action is
invoked on the timer's tick event. This can be useful to defer execution until after the
current event loop iteration. If useTimer is false, the action is
executed immediately. This method is not thread-safe; concurrent calls may result in the action being
executed more than once.