Objective:
Press a button on UI which triggers the process of calling a Model function 3 times with a 2 second interval between each call.
During this process the rest of the program should be running concurrently( in a separate thread ).
Event handler for the button, which sets up the thread and calls the Model function in question via the controller(MVC).
Code: Select all
void MAIN_FRAME::OnButtonClick_CallModelFuncAtIntervals( wxCommandEvent& WXUNUSED( event ) )
{
std::thread t(&MVC::ModelFuncAtIntervals, this->_MVC);
t.join();
}
Code: Select all
void MVC::ModelFuncAtIntervals()
{
for ( int i = 0; i < 3; i++ )
{
this->Model->Func();
std::this_thread::sleep_for(std::chrono::seconds(2));
}
}
Code: Select all
void Model::Func()
{
My_Diagnostic.log("Refresh!");
....Do stuff!
}
---------
The problem is while this process is running the UI is frozen and unresponsive.
What is required to make this process execute concurrently with the main program?