C ++ application portal
Maybe you are a little confused about the entrance to designing an application. Here are some simple routines.
// You write an app class on your own and inherit from a Thread class. Of course, you can encapsulate this thread class on your own, or you can find the open-source class MyApp: XxThread {public: bool NeedStop (); void NoticeStop ()} void Run (){
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 because of the existence of while, the main thread will 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 until the sub-thread stops running and then exit to start the APP, in two cases, one is in the command line program // if it is called in main, it must be joined, the main thread can exit int main (int argc, char ** argv) {MyApp: GetInstance ()-> Start (); MyApp: GetInstance () earlier than the sub-thread () -> Join ();} another type is in MFC. For example, in a button clicking event, you can directly call MyApp: GetInstance ()-> Start (). This time, no need to join, because unless you close the MFC program, it will not exit void CTxServerWinDlg: OnBnClickedButton1 () {MyApp: GetInstance () -> Start ();}