Thread: MFC Controls and Thread Safety :: MFC

  1. #1
    Registered User
    Join Date
    Nov 2001

    MFC Controls and Thread Safety :: MFC


    I read an interesting thread at a MSDN newgroup on MFC and thread safety. Its author asks about why a thread causes the process to hang when you pass to the thread points to MFC control objects (CListrCtrl, CEdit, CTreeCtrl, etc).

    I remember something similar to what the author of thread asks from a application I just finished. I found that you can make changes to MFC controls from threads via pointers to the controls. Everything works well until you call WaitForSingleObject(), or WaitForMultipleObject(), etc. In other words, the process hangs if you call WaitForSingleObject() when the thread is updating an MFC control.

    Ivan Lalis posted an interesting solution involving MFC controls handles. He writes that one solution is to pass in the worker threads handles to MFC controls instead of pointers.

    UINT theWorkerThread(LPVOID pParam)
       CListCtrl theList;
       return 0;
    I would like to know what is the safest solution to this problem? Secondly, in terms of Lalis' solution, do you create and attach, for example, one CListCtrland for the entire life-time of the thread?

    Last edited by kuphryn; 12-06-2002 at 11:41 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tab controls - MFC (revived)
    By Robert602 in forum Windows Programming
    Replies: 1
    Last Post: 01-22-2002, 12:32 PM