Click here to Skip to main content
15,880,725 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How: each doc/view in own thread (advanced) Pin
#realJSOP13-Jul-01 1:41
mve#realJSOP13-Jul-01 1:41 
GeneralRe: How: each doc/view in own thread (advanced) Pin
EiSl13-Jul-01 3:12
EiSl13-Jul-01 3:12 
GeneralRe: How: each doc/view in own thread (advanced) Pin
#realJSOP13-Jul-01 7:29
mve#realJSOP13-Jul-01 7:29 
GeneralRe: How: each doc/view in own thread (advanced) Pin
EiSl15-Jul-01 19:47
EiSl15-Jul-01 19:47 
GeneralRe: How: each doc/view in own thread (advanced) Pin
#realJSOP16-Jul-01 0:29
mve#realJSOP16-Jul-01 0:29 
GeneralRe: How: each doc/view in own thread (advanced) Pin
EiSl16-Jul-01 21:41
EiSl16-Jul-01 21:41 
GeneralRe: How: each doc/view in own thread (advanced) Pin
#realJSOP17-Jul-01 1:53
mve#realJSOP17-Jul-01 1:53 
GeneralRe: How: each doc/view in own thread (advanced) Pin
Stephen C. Steel13-Jul-01 13:11
Stephen C. Steel13-Jul-01 13:11 
I don't think that a thread per doc/view is a good approach: there are a lot of complications, and it doesn't change the fact that only one thread can update the GUI at a time (the GDI calls are serialized).

A much better approach, which I have used successfully in a couple of commercial applications, is to have one worker thread per doc, with the original GUI thread handling all the views. The worker threads can update each documents contents to reflect the input recieved via TCP/IP independently.

You can run into some problems invoking window related functions from a worker thread because of the need to link C++ objects like CWnds with the associated Windows HWND (look up handle maps in the VC++ docs if you want the messy details). As long as the worker threads stick to updating the data in the CDocument derived class, you won't have problems. You may have to use critical sections or some other form of synchronization to stop the GUI thread from reading partially updated document contents though.

I get around the handle map problem by defining a user message UM_UPDATE_VIEWS. The worker threads POST (not send) this message to the main window after changing the document contents. The main GUI thread processes this message, by calling CDocument::UpdateAllViews() for the CDocument derived object passed as a pointer in the LPARAM. This way UpdateAllViews() gets invoked by the main GUI thread, so there is no problem with handle maps.



Stephen C. Steel
Kerr Vayne Systems Ltd.
GeneralCOleDateTime Pin
12-Jul-01 23:19
suss12-Jul-01 23:19 
GeneralRe: COleDateTime Pin
markkuk13-Jul-01 8:12
markkuk13-Jul-01 8:12 
GeneralGetting parts of the Platform SDK Pin
12-Jul-01 23:15
suss12-Jul-01 23:15 
GeneralRe: Getting parts of the Platform SDK Pin
EiSl12-Jul-01 23:40
EiSl12-Jul-01 23:40 
GeneralStrange implementation in one of the samples... Pin
EiSl12-Jul-01 23:12
EiSl12-Jul-01 23:12 
GeneralCPropertySheet::RemovePage in MFC causes memory leak Pin
Serge Desmedt12-Jul-01 23:11
professionalSerge Desmedt12-Jul-01 23:11 
GeneralRe: CPropertySheet::RemovePage in MFC causes memory leak Pin
Tomasz Sowinski13-Jul-01 0:00
Tomasz Sowinski13-Jul-01 0:00 
GeneralRe: CPropertySheet::RemovePage in MFC causes memory leak Pin
Serge Desmedt13-Jul-01 5:33
professionalSerge Desmedt13-Jul-01 5:33 
GeneralSaving HICON to a file Pin
Deian12-Jul-01 22:45
Deian12-Jul-01 22:45 
GeneralWhy not delete the CSingleDocTemplate Pin
ndkk12-Jul-01 22:01
ndkk12-Jul-01 22:01 
GeneralProblem in RegQueryValueEx Pin
Yamuna12-Jul-01 21:35
Yamuna12-Jul-01 21:35 
GeneralByteBuffer Pin
12-Jul-01 21:12
suss12-Jul-01 21:12 
GeneralRe: ByteBuffer Pin
Tomasz Sowinski13-Jul-01 0:20
Tomasz Sowinski13-Jul-01 0:20 
GeneralScrollview & Zoom Pin
12-Jul-01 20:14
suss12-Jul-01 20:14 
GeneralRe: Scrollview & Zoom Pin
Tomasz Sowinski13-Jul-01 0:14
Tomasz Sowinski13-Jul-01 0:14 
GeneralCaller ID Pin
Vishnu Vijayan12-Jul-01 20:01
Vishnu Vijayan12-Jul-01 20:01 
GeneralRe: Caller ID Pin
Michael P Butler12-Jul-01 22:49
Michael P Butler12-Jul-01 22:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.