Window frame hang due to misuse of thread

假如想象 提交于 2019-12-12 05:57:09

问题


I am getting a database table value in wxListCtrl, (data can be large so I am using wxThread) Child thread send row to Main thread and main thread fill it in wxListCtrl, everything is going good but when I m trying to close the frame , it is giving me unexpected result. at the close button , I am invoking a new frame, sometime it opens and some time not, my code is:-

 if(thread_object_holder->IsAlive())
        {
            wxPuts(wxT("live"));
            thread_object_holder->Pause();
            wxMessageDialog *msg = new wxMessageDialog(this,wxT("You want to quit"), wxT("Quit Login Report") ,wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
            if ( msg->ShowModal() == wxID_YES )
            {
                thread_object_holder->Delete();
                temp_back_frame *obj= new temp_back_frame();
                this->Destroy();
                obj->Show(true);
            }
            else
            {
                thread_object_holder->Resume();
            }
        }
        else
        {
            wxPuts(wxT("dead"));
            wxMessageDialog *msg = new wxMessageDialog(this,wxT("You want to quit"), wxT("Quit Login Report") ,wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
            if ( msg->ShowModal() == wxID_YES )
            {
                thread_object_holder->Delete();
                temp_back_frame *obj= new temp_back_frame();
                this->Destroy();
                obj->Show(true);
            }

        } 

there are only 7 row in table, during the filling record if I press the button, everything is fine there but once 7 row placed in ListCtrl { I think now thread will be destroy } , me no data to put to listctrl, we press close button then sometime new frame open, some time frame hang, I THINK THREAD IS RESPONSIBLE FOR THIS BUT HERE I TAKE PROPER PRECAUTION TO HANDLE THE THREAD, please let me know, where I am wrong.


回答1:


Basicially problem was Thread, wxThread, by default thread is Detatched , it automatically delete when finish working. here during thread alive when we check if( obj->IsAlive ) , no problem but when thread end then we checked this
` if(obj -> IsAlive ) showing problem because when thread delete , there are no object of thread.still we are checking this. [ it was the main problme ]. i use a extern variable to check thread is live or dead , now my code is working fine.



来源:https://stackoverflow.com/questions/5534924/window-frame-hang-due-to-misuse-of-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!