简体   繁体   English

如何使用按钮事件暂停和恢复wxThread

[英]how to pause and resume wxThread with button event

I am trying to fill wxListCtrl with the database, and for this I'm using wxThread concept. 我试图填补wxListCtrl与数据库,为此我使用wxThread概念。 I want to add two buttons in the frame, for pause and resume thread. 我想在框架中添加两个按钮,用于暂停和恢复线程。 How can this possible? 这怎么可能呢?

Finally, I got the solution - I was trying to pause and resume thread with the button event. 最终,我找到了解决方案-我试图通过button事件暂停和恢复线程。 For this 为了这

  1. Take two buttons wxButton *stop, *resume 带两个按钮wxButton *stop, *resume
  2. Create two button events: 创建两个按钮事件:

     void onstopbuttonclick(wxCommandEvent & event); void onresumebuttonclick(wxCommandEvent & event); 
  3. At stop button event, write: 在停止按钮事件中,输入:

     void login::onstopbuttonclick(wxCommandEvent& evt) { temper->Pause();//temper is object of thread class } 
  4. At resume button event, write: 在“恢复”按钮事件中,输入:

     void login::onresumebuttonclick(wxCommandEvent& evt) { temper->Resume(); } 
  5. Write finally in Entry() method: 最后在Entry()方法中编写:

     if(TestDestroy()) { return NULL; } 

    Write this before your thread code, when you click stop button this condition will be true that time and thread will not perform any work that time. 在您的线程代码之前编写此代码,当您单击“停止”按钮时,此时的条件将成立,并且线程在该时间将不执行任何工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM