Delete OpenGLAppComponent from its own thread

Ok, before yelling at me because of the subject, here is my case: I need to open a window, do some rendering and other stuff without user interaction and then close the window (i.e. delete the OpenGLAppComponent). This is required for some automatic testing. The problem is that you, of course, cannot delete it from its own thread which will be the case. What is the appropriate Juce way of doing this? I guess I need to dispatch the deletion to the message thread somehow, but I could not really figure it out.

There are lots of ways to call something asynchronously: e.g. Timer, CallbackMessage, AsyncUpdater, MessageManager::callAsync, etc..!

Thank you. The problem was solved by doing:

    void QAHandler::destroyQAWindowOnMessageThread(const int& compositeId)
        const ScopedLock sl(mLock);
        std::function<void(void)> destroyQAWindowFunction = [this, compositeId]() { this->destroyQAWindow(compositeId); };

where the compositeId is just and identifier for the window. The destroyQAWindow() function is then called on the message thread.