Updating View from WinThread
-
I'm developing a VC++ SDI program that needs to have a couple threads running. The main thread starts by pressing a button in the toolbar which is processed in the Document. This thread reads from a data file once a second, this data is stored as variables in the Document, after this data is read and stored I need to update the View, however I have not been successful at having the View update with out crashing the program. I have the program setup as a SDI and have added a CWinThread Class. I have been successfull at reading the data with the class but just not updating the View. Any help with this problem would be great. J Guds Masters Student Kansas University
-
I'm developing a VC++ SDI program that needs to have a couple threads running. The main thread starts by pressing a button in the toolbar which is processed in the Document. This thread reads from a data file once a second, this data is stored as variables in the Document, after this data is read and stored I need to update the View, however I have not been successful at having the View update with out crashing the program. I have the program setup as a SDI and have added a CWinThread Class. I have been successfull at reading the data with the class but just not updating the View. Any help with this problem would be great. J Guds Masters Student Kansas University
The UI is "owned" by the primary thread and should only be updated by it. All other threads should post (not send) a message to the primary thread indicating an update needs to be done. Check out this article.
A rich person is not the one who has the most, but the one that needs the least.
-
I'm developing a VC++ SDI program that needs to have a couple threads running. The main thread starts by pressing a button in the toolbar which is processed in the Document. This thread reads from a data file once a second, this data is stored as variables in the Document, after this data is read and stored I need to update the View, however I have not been successful at having the View update with out crashing the program. I have the program setup as a SDI and have added a CWinThread Class. I have been successfull at reading the data with the class but just not updating the View. Any help with this problem would be great. J Guds Masters Student Kansas University
I suggest you to take a luck at example from “msdn” documentation “MTMDI” that demonstrates an MFC User Interface Thread. For avoiding potential problems when programming multithreaded applications you need to respect some rolls or programming tips that is also described in “mfc” documentation. Ex: - You can't have two threads manipulating the same object.., if you need this you need to protect such access with appropriate Win32 synchronization mechanisms... - A thread can access only MFC objects that it created, a worker thread cannot perform a calculation and then call a document’s “UpdateAllViews” member function to have the windows that contain views on the new data modified, because the map from CWnd objects to HWNDs is local to the primary thread. There are several ways around this problem: you can pass individual handles (such as an HWND) rather than C++ objects to the worker thread, or you can create new user-defined messages corresponding to the different tasks your worker threads will be performing and post these messages to the application’s main window using PostMessage. If this little help is not enough for your problem send me a sample of your code and I will help you. CC.