I have compressed a problem I
- I have a VC ++ 6.0 Creates a simple dialog app.
- I start a thread before calling the main dialog (.)
- I sometimes get the app off - sometimes it gets 10 seconds or more Locks for more
What's the reason for this? I have tried _beginthread (), _beginthreadex () and AfxBeginThread () they all do the same thing.
If I add a sleep (50) after the DoModal () call (when the GUI processing is finished), then the program is ending without problems every time.
What was the reason for reducing this problem to me that I have a Win32 DLL that does the same thing in my DLL is a thread and I have seen that using my DLL Sometimes it will take some time to eliminate DLL and simplify the programs as a result of the same thing - which I have described above.
Below is a code that I have added to a bug-standard MFC communication app:
UINT thread (zero *) {for (;;) {sleep ( 50); } Afsendrade (0); Return 0; } ///////////////////////////////////////////////// //////////////////////////// CThreadTest2App Initialization BOOL CThreadTest2App :: InitInstance () {AfxEnableControlContainer (); // Standard Initialization // If you are not using these features and wish to reduce the size of your final executable, you should remove the following from the specific initialization routine you do not need. #ifdef_AFXDLL enabled 3dControls (); // Call it while using MFC in the shared DLL #ELse enabled 3 dControlsStatic (); // Call MFCs permanently when adding them to #endif AfxBeginThread (Thread, 0); CThreadTest2Dlg DLL; M_pMainWnd = & amp; Dlg; Int nResponse = dlg.DoModal (); // sleep (50); // Works when I add it ????? If the dialog has been discontinued, return to FALSE (nResponse == IDOK) {} else if (nResponse == IDCANCEL) {} // so that we exit the application instead of starting the application pump. return false; } Can someone help me close my app properly?
thanks paul
OK, in your thread, you have more endless loop and AfxEndThread !
If you want to stop the thread from the outside, you have to code the signaling system in it, and if you have to stop, check it inside the loop.
Comments
Post a Comment