Implemented invokeInThread() family of functions.
The function handleException() is now thread-safe and can be used outside the gui thread.