Click here to Skip to main content
15,861,168 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
This works but the interface freezes until the function is complete
C#
void CJewelDoc::OnBstart()
{
    // TODO: Add your command handler code here
    m_Model.Solver();
}



this compiles but the function isn't called and the interface freezes it appears the thread hangs

C#
void CJewelDoc::OnBstart()
{
    // TODO: Add your command handler code here
    std::thread t(&CModel::Solver, &m_Model);
    t.join();
}
Posted
Comments
barneyman 2-Jul-15 20:15pm    
those two implementations fundamentally do the same thing, you'd need to detach the t object for it to run in parallel

as regards the 'appears to hang' - feel free to break into it with the debugger and find out what it's doing

1 solution

Hi, in the first case, the interface freezes because it is the main thread that is executing the "Solver" function and it is not handling the message queue any more as long as inside the "Solver" function there is no getMessage and no message handling routine.

I would declare the "Solver" function as static inside the class and then start the thread with the CreateThread function:

In Model.h
class CModel
{
    static UINT Solver(LPVOID pParam);
}


In Model.cpp
UINT CModel::Solver(LPVOID pParam)
{
    // Whatever you want to do in this function
    return 0;
}


And finally:
void CJewelDoc::OnBstart()
{
    // TODO: Add your command handler code here
    CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)CModel::Solver, NULL, NULL, NULL);
}


Should be quite the same as your second solution, but it works for me without freezing the interface..
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900