Re: Thread Communication in between UI and working thread
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Sun, 23 Mar 2008 18:36:11 -0500
See my essay on worker threads on my MVP Tips site. Note that you should, whenever
possible, avoid the use of CRITICAL_SECTION or Mutex between threads, that is, design so
they are not actually required because there is no concurrent access to data. Life
becomes simpler if you can avoid needing this level of synchronization.
joe
On Tue, 18 Mar 2008 10:33:58 +0800, asm23 <asmwarrior@xxxxxxxxx> wrote:
Hi, I'm using a SDI-based MFC application. and to create a workingJoseph M. Newcomer [MVP]
thread, I add a static member function to CMainFrame. Then, I want to
know how does the working thread report some message to CMainFrame, like
a CString.
here is my method I want to use(pseudocode):
//-------------Class
class CMainFrame : public CFrameWnd
{
...
static DWORD WINAPI ThreadProc(void* pParameter);
}
//--------------Thread
DWORD CMainFrame::ThreadProc(void* pParameter){
CMainFrame* This = (CMainFrame*) pParameter;
...
CString * ptrString = new CString("xxxx") ;
...
This->PostMessage(WM_XXX, (unsigned int)ptrString, 0);
}
//----------------Message handler
afx_msg LRESULT CMainFrame::OnXXXX(WPARAM wParam, LPARAM lParam)
{
CString * ptr = (CString *)wParam;
......
return 0;
}
Note: This is the pointer to CMainFrame.
Is it a good method? Or, there are other better alternative. Since that
the Postmessage can only take two parameters, how can I pass a string or
a block of data. Are there any tutorials cover this topic? Thanks!
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Prev by Date: Re: CEdit SetWindowText rediculously slow
- Next by Date: Re: LocaleName->LCID, "da"->1030
- Previous by thread: Re: Thread Communication in between UI and working thread
- Next by thread: Burberry Alma with Black Trim Replica AAA, Fake HandBags Cheap
- Index(es):
Relevant Pages
|