For thread synchronization issues, there is a further understanding: See the article I wrote about multithreaded synchronization (modified): http://blog.9cbs.net/yjgx007/94559. ASPX, the main thread a Wait for another thread b to continue, in the thread B, the main thread A is updated, which involves synchronous problems and the possible deadlock problems, synchronous problems in modified articles It is clear that the analysis of the deadlock between the thread may produce: In the waiting thread B, update the interface A of the main thread A. If it is not possible to properly process the problem of two threads synchronization, it is possible to cause Dead lock between the two-threading, look at the following code: uint cmsitestdlg :: updateDeviceContent (lpvoid pParam) {cmsitestdlg * pdlg = (cmsitestdlg *) PParam; int i = 0; do {pdlg-> m_progress.setpos (i); // Update the progress bar Sleep (500) in thread a;} while (i <10);
Return 0;}
void CMsiTestDlg :: OnButton1 () {MSG msg; CWinThread * m_pUpdateThread = AfxBeginThread (UpdateDeviceContent, (LPVOID) this / *, THREAD_PRIORITY_BELOW_NORMAL * /); if (m_pUpdateThread) {while (:: WaitForSingleObject (m_pUpdateThread-> m_hThread, INFINITE)! = WAIT_OBJECT_0) // Start Waiting Threads B to End (Wait_Object_0 will return to Wait_Object_0) PeekMessage (& MSG, NULL, NULL, NULL, PM_REMOVE); // Get the current thread message (may be a thread may be B thread) Remove the message from the message queue (& MSG); // Re-distribute the message ...}