Portal for C + + applications

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.