Maybe you're a little confused about designing an application, and I'm here to talk about some simple routines.
You write an app class yourself, inherit from a thread class, of course, this thread class you can package yourself, you can also find the open source class Myapp:xxthread{public:bool needstop (); void Noticestop () <span style= "font-family:arial, Helvetica, Sans-serif;" >}</span><span style= "font-family:arial, Helvetica, Sans-serif;" > void Run () {</span><span style= "font-family:arial, Helvetica, Sans-serif;" > </span>
while (1) {if (m_bneedstop) {break; }}}private:bool m_bneedstop;} It is best to call this function in the main thread, because this ensures that while the main thread does not exit immediately,//if it is not called in the main thread, there must be another mechanism to ensure that the main thread will wait for the child thread to run and then exit the startup app, in two cases, one in the command line program// If it is called in Main, then it must join so that the mainline Cheng thread exits int main (int argc, char** argv) {myapp::getinstance ()->start () earlier; Myapp::getinstance ()->join ();} The other is in MFC, for example, in a button click event, directly call Myapp::getinstance ()->start (); this time, do not need to join, because, unless you actively shut down MFC program, otherwise he will not quit void Ctxserverwindlg::onbnclickedbutton1 () {myapp::getinstance ()->start ();}
Portal for C + + applications