Some details about multithreading
Author: coolnerd-threaded program, if the thread would like to report the state of the interface window, there are two methods of operation, one is the method through messages, due to the volume of messages carried in the message itself sometimes does not buy used, often just a pointer to a message parameter The message object is pointer, and the message object often needs to be generated in the heap memory, "because the thread can continue to wait for the message processing, continue, so if the message object is often the message object, it is still handled, it is threaded again. Modify. So use the heap object.) The interface accepts DELETE after the message object. However, after the interface exits, if the thread still generates a new message object, the message object is not released, so in this case, the interface is accepted Before the WM_CLOSE message will be released, wait for the thread to completely exit after it is true. The second method of the thread to the interface report status is to simultaneously (wait until the synchronization is called synchronization) during the execution of the thread. Under this mechanism, pay attention to whether the interface display is needed to see if the interface window still exists (using the iswindow function implementation). This seems to be perfect, but it is not perfect, because if there are multiple view small windows, such as Multiple CSPLITTERWND, only in the processing function of a CSPLitterWnd's WM_CLOSE message, other CSPLitterWnd is exited as usual, still have problems, so grasping the root: User uses the menu to exit or click the X button of the FRMAE window to quit, accept The first is FrameWnd, which needs to be threaded in the WM_Close function of FrameWnd.! In addition, how often the thread is in the palm of the Document class, how does Frame access to the Document object? FrameWnd does not directly provide Document's function.Document, view The order of the three of FrameWnd is: doc-> frMae-> View, at the time of the View :: InitUpdate () function, you can do the following code: cmainframe * frm = (cmainframe *) (AFXGetApp () -> m_pmainwnd) FRM-> PDOC = getDocument (); additional: Note You need to capture WM_Close, not the WM_DESTROY message, because the WM_Close message is first in the latter. In addition, check the following code: Void CthreadList :: UpdateThread (int ID, CString Client, CString MSG) ) {EntercriticalSECTION (& CThread List :: csupdatethread; {Int itemcount = m_listctrl.getItemcount (); // listctrl Up to 65535 records IF (id> itemcount) {for (int i = 0; i