Search code examples
c++wxwidgets

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. I want to add two buttons in the frame, for pause and resume thread. How can this possible?


Solution

  • Finally, I got the solution - I was trying to pause and resume thread with the button event. For this

    1. Take two buttons 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:

      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.