CriticalSection.Enter

From Xojo Documentation

Method

CriticalSection.Enter()

Supported for all project types and targets.

Attempts to get a lock on the resource managed by the CriticalSection.

Notes

When the call to Enter succeeds, the function returns and your code has exclusive access to the protected resource. If the lock cannot be obtained immediately, Enter will block the current thread from continuing to run. It will wait for the resource to become available.

Enter differs from the Signal method of the Semaphore class in that it can be called multiple times from the currently executing thread. If the calling thread already owns the lock, the method returns immediately. This makes CriticalSections very useful for calling a method recursively.