Properly dispatching messages to the UI thread.