Calling MessageManager::callAsync to update UI components in run method of thread

Hi,

I have created component inherits from ThreadWithProgressWindow and in run which update model and call listener which eventually call component resized(), which is causing the crash.

If I change following to update UI, it loads UI after some time, what could be the issue, what am i doing wrong?
MessageManager::callAsync([=]
{
resized();
// call other memeber method
});

    class MainComponent  : public Component,
                           public DModel::DListener,
                            public ThreadWithProgressWindow
    {
    MainComponent::MainComponent()
    {
    // to get update when model change
    model = new DModel();
    model.addListerner(this);
launchThread(1);
    }
    void dUpdate(const String& str){
    resized(); // crashes the code
    }
    void run()
    {
    while(!threadStop)
        {
    // when data count reach 100 
    if(datacount == 10)
    {
    threadStop = true;
                break;
    }
    updateModel(model)
        }
    }
    private:
    DModel * model;
    }

    class DModel{
    class DataListener
        {
        public:
            /** Called when the button is clicked. */
            virtual void dUpdate(const String& str) = 0;
    }
    public:
    void dataUpdateSend(const String& str)
    {
    dataListeners.call( &DataListener::dUpdate, str);
    }
    }

    void updateModel(DataModel* model)
    {
    model->dataUpdateSend("abc");
    }

Any time you use callAsync, you need to verify the object you are referencing still exists by the time the callback happens. Either with SafePointer or WeakReference.

1 Like

Thanks for Info. I will check with safePointer to make sure component exist.

Actually the crash is not happening while I callAsync, but when i dont use it.
And another thing is when use callAsync UI repaint for images take time and it does not look real time.