From Xojo Documentation

Revision as of 21:03, 13 February 2022 by Gperlman (talk | contribs) (Example)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Semaphore.TrySignal() As Boolean

New in 2005r1

Supported for all project types and targets.

This is a more friendly version of the Signal method that gives you a sneak-peek to determine whether there is a lock available.


If there is a lock available, you are granted the lock and TrySignal returns True. When you are finished with the resource, call Release to give it back to the Semaphore. If the lock is not available, you do not wait for it. Instead, TrySignal returns False to let you know. Do not attempt to use the resource after it returns False because you are likely to collide with another thread.


This example tests whether the lock is available before trying to use the resource.

// Want to make sure that only the right thread
// gets in here. One at a time!
If mLock.TrySignal Then
// Now that we're here, we can change the resource
SharedResource.Value = value
AccessText.Text = id.ToString

// And now that we've done something with the
// resource, we want to release our lock on it
End If