【问题标题】:how to pause and resume wxThread with button event如何使用按钮事件暂停和恢复 wxThread
【发布时间】:2011-02-23 05:59:50
【问题描述】:

我正在尝试用数据库填充 wxListCtrl,为此我使用wxThread 概念。我想在框架中添加两个按钮,用于暂停和恢复线程。这怎么可能?

【问题讨论】:

    标签: c++ wxwidgets


    【解决方案1】:

    最后,我得到了解决方案 - 我试图通过按钮事件暂停和恢复线程。为此

    1. 取两个按钮wxButton *stop, *resume
    2. 创建两个按钮事件:

      void onstopbuttonclick(wxCommandEvent & event);
      void onresumebuttonclick(wxCommandEvent & event);
      
    3. 在停止按钮事件中,写:

      void login::onstopbuttonclick(wxCommandEvent& evt)
      {
          temper->Pause();//temper is object of thread class      
      }
      
    4. 在恢复按钮事件中,写:

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

      if(TestDestroy())                                                   
      {
          return NULL;
      }
      

      在你的线程代码之前写下这个,当你点击停止按钮时,这个条件将在那个时候为真,那个时候线程不会执行任何工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多