What is an IllegalLockingException?

Hi,

can anyone tell me what an IllegalLockingException is? The docs don’t mention this exception. The error message also isn’t really helpful: The thread which Signaled the Mutex must be the thread to Release the Mutex.

The app is only a helper app and mainly consists of a timer. The code is:

if appMutex <> nil then appMutex.leave

Mac OS 10.9, Xojo 2013r4, Cocoa.

IllegalLockingException is thrown when you get the Enter and Leave calls in the wrong order. For instance, in your code, what’s probably happening is that the mutex object has been created, but appMutex.Enter (or .TryEnter) hasn’t been called yet. So the error is, you can’t leave before you enter.

This is funny and of course worked in previous incarnations of Xojo:

In app.open I have:

// try to get a lock on mutex, immediately quit if a lock can’t be obtained
appMutex = new Mutex(getHelperBundleID) //using the Bundle Identifier
if not appMutex.TryEnter then quit

In app.close I have:

// free the lock on mutex
if appMutex <> nil then appMutex.leave

If a first version of the helper app is running and I now try to run it a second time, the debugger gets the IllegalLockingException on App.Close. Can I just ignore the exception?

I’d wrap the code in app.close in a try-catch so you are specifically ignoring this instance. Blindly ignoring the exception may cause you grief later.

Thanks, that worked!