title: Converting a Console Program into an MFC app (Thread issues) (Pleora SDK)
body: <p>Back to stackoverflow with another question after hours of trying on my own haha.
  Thank you all for reading this and helping in advance.</p>
  <p>Please note the console program has following functionalities:</p>
  <blockquote>
  <ol>
  <li>connect to a frame grabber</li>
  <li>apply some configs</li>
  <li>store the incoming data (640 * 480 16-bit grayscale imgs) in a stream of buffers inside a while loop</li>
  <li>Exits the while loop upon a key press.</li>
  <li>disconnect from device</li>
  </ol>
  </blockquote>
  <p>And I'm only adding the displaying the images functionality on the MFC GUI app. In short,</p>
  <blockquote>
  <p>i) Converting a console app to an MFC app (dialog based)</p>
  </blockquote>
  <blockquote>
  <p>ii) decided to use thread for displaying images, but DK how to properly exit from thread when there are certain tasks to be done (such as call disconnectFromDevice(); freeBuffers();, etc) before exiting the thread.</p>
  </blockquote>
  <blockquote>
  <p>iii) have tried making the while loop condition false but didn't work
  ( I actually want this to be a callback function that's called repeatedly but IDK how to implement it inside a thread)</p>
  </blockquote>
  <blockquote>
  <p>iv) forcing AfxEndThread didn't work and it's not even the way it should be done (I think).</p>
  </blockquote>
  <p>So my question is,</p>
  <p><strong>1. Are you supposed to use a while loop to excuete a certain job that should repeatedly be done? If not, do you have to implement a callback inside a thread? Or use Windows message loop? Why and how? Please provide a hello-world-like sample code example</strong></p>
  <p>(for example, you are printing &quot;hello world&quot; repeatedly inside a thread with a condtion in an MFC GUI app. How do you update or check the condition to end the thread if you can't just AfxEndThread() inside the threadproc)</p>
  <p><strong>2. If it's ok with a while, how do you exit from the while loop, in other words how do you properly update the exit condition outside the thread the while loop's in?</strong></p>
  <p>Please refer to the source code in the provided link</p>
  <p><strong>ctrl+F OnBnClickedConnectButton, AcquireImages and OnBnClickedDisconnectButton</strong></p>
  <p><a href="https://github.com/MetaCortex728/img_processing/blob/main/IR140Dlg.cpp" rel="nofollow noreferrer">https://github.com/MetaCortex728/img_processing/blob/main/IR140Dlg.cpp</a></p>