开发者

Window frame hang due to misuse of thread

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜