Semaphore.TrySignal

From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!
Method

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.

Notes

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.

Example

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
mLock.Release
End If