+void MyFrame::OnStartThread(wxCommandEvent& WXUNUSED(event) )
+{
+ MyThread *thread = CreateThread();
+
+ if ( thread->Run() != wxTHREAD_NO_ERROR )
+ {
+ wxLogError("Can't start thread!");
+ }
+
+ SetStatusText("New thread started.", 1);
+}
+
+void MyFrame::OnStopThread(wxCommandEvent& WXUNUSED(event) )
+{
+ // stop the last thread
+ if ( m_threads.IsEmpty() )
+ {
+ wxLogError("No thread to stop!");
+ }
+ else
+ {
+ m_critsect.Enter();
+
+ wxThread *thread = m_threads.Last();
+
+ // it's important to leave critical section before calling Delete()
+ // because delete will (implicitly) call OnThreadExit() which also tries
+ // to enter the same crit section - would dead lock.
+ m_critsect.Leave();
+
+ thread->Delete();
+
+ SetStatusText("Thread stopped.", 1);
+ }