File Change Event CDialog
-
Hello, I am working on a project that requires file-change-notification to a CDialog. Currently, I am trying to use the CFileChangeEventClass[^] by Fanky Braem. However, when I get notified of a change, and I try to call UpdateData(), the program crashes. I believe that Franky explains what the problem is: "A thread can access only MFC objects that it created. This is because temporary and permanent Windows handle maps are kept in thread local storage to ensure protection from simultaneous access from multiple threads." and provides a solution for a doc/view scenerio. Can anyone help me in figuring out how to solve this for the CDialog case? Thanks a lot, ----------------- Genaro
-
Hello, I am working on a project that requires file-change-notification to a CDialog. Currently, I am trying to use the CFileChangeEventClass[^] by Fanky Braem. However, when I get notified of a change, and I try to call UpdateData(), the program crashes. I believe that Franky explains what the problem is: "A thread can access only MFC objects that it created. This is because temporary and permanent Windows handle maps are kept in thread local storage to ensure protection from simultaneous access from multiple threads." and provides a solution for a doc/view scenerio. Can anyone help me in figuring out how to solve this for the CDialog case? Thanks a lot, ----------------- Genaro
Do the file change notificaiton/waiting in a secodnary thread. Post messages to your main thread. Process those messages in the main thread. Don't try ot directly update controls from the secodnary thread which processed the file notification. You can look into ON_REGISTERED_MESSAGE. // example for ON_REGISTERED_MESSAGE const UINT wm_Find = RegisterWindowMessage( FINDMSGSTRING ); BEGIN_MESSAGE_MAP( CMyWnd, CMyParentWndClass ) ON_REGISTERED_MESSAGE( wm_Find, OnFind ) // ... Possibly more entries to handle additional messages END_MESSAGE_MAP( ) Post the registered message fromt he notiifcaiton thread. When the main dialog receives it, then call the updatedata. This should work fine for you.