Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone..

Am working on the Trading Platform. I'm having a situation like where i need to run two operations ( Open & Close Operations ) infinitely. let me elaborate it clearly :

C++
void CTradingPlatform : OnBnClickedOPEN()
{
  while(1)
  {
    // Based on some conditions.. //code for the Open Opeartion here ...
  }

}

void CTradingPlatform : OnBnClickedCLOSE()
{
 while(1)
 {
  // Based on some conditions.. code for CLOSE Operation here..
 }
}


Here the problem is.. I cant run these two while loops at a time. I can run only one of them. These two while loops must run at a time. Is there any solution for this.. Please suggest me on this..

Thank you all :)
Posted

1 solution

Unless the loops are synchronized in some rigid manner, so you could write them in a single loop, the only way to do this is to execute them in different threads. As UI is also involved (otherwise why would you use MFC?), even one loop will need a separate thread. In other words, for two loops, you will add at two threads to existing UI thread, to have at least three threads in total.

—SA
 
Share this answer
 
Comments
Guru_C++ 15-Jan-13 4:11am    
yeah.. I have created two threads like this..

UINT Thread1(LPVOID lParam)
{
while(1) {
//Code for Open Operation..
}

return(1);
}

UINT Thread2(LPVOID lParam)
{
while(1)
{
//Code for Close Operation..
}

return(1);
}

void CTradingPlatform : OnBnClickedOPEN()
{
AfxBeginThread(Thread1,0);

}

void CTradingPlatform : OnBnClickedCLOSE()
{
AfxBeginThread(Thread2,0);
}

Now this works fine.. Thank you..
Sergey Alexandrovich Kryukov 15-Jan-13 10:39am    
This is great. Such a pleasure to help someone who can actually get it and make things working.
Good luck, call again.
—SA

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