窗户框架因滥用螺纹而挂起 [英] Window frame hang due to misuse of thread

查看:120
本文介绍了窗户框架因滥用螺纹而挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在wxListCtrl中获取数据库表值((数据可能很大,所以我正在使用wxThread)子线程将行发送到Main线程,并且主线程将其填充到wxListCtrl中, 一切都很好,但是当我尝试关闭框架时,这给了我意外的结果.在关闭按钮上,我正在调用一个新框架,有时它打开,而有时没有,我的代码是:-

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);
            }

        } 

表中只有7行,在填充记录期间,如果我按一下按钮,那里一切都很好,但是一旦将7行放入ListCtrl {我认为现在线程将被破坏},我就没有数据可放入listctrl,我们按下关闭按钮,然后有时打开新框架,有时挂起,我认为这种情况是负责的,但在这里我采取了适当的预防措施来处理这种情况,请告诉我,我哪里错了.

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.

推荐答案

基本问题是线程wxThread,默认情况下,线程为Detatched,完成工作后会自动删除.在这里,当我们检查if(obj-> IsAlive)时,在线程处于活动状态时,没问题,但是当线程结束时,我们对此进行了检查
` if(obj-> IsAlive) 显示问题的原因是,当线程删除时,没有线程对象. [这是主要问题].我使用一个extern变量来检查线程是存活还是死亡,现在我的代码可以正常工作.

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.

这篇关于窗户框架因滥用螺纹而挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆