Board index » Visual Studio » CWinThread::CreateThread
|
czarrow
|
|
czarrow
|
CWinThread::CreateThread
Visual Studio179
Questions regarding CWinThread::CreateThread 1) Does it start a "UI" thread or a "worker" thread (or both!)? If both, how is this distinguished? 2) Where does thread execution begin? (A pointer to a function is not specified on the CWinThread::CreateThread() function call.) Thanks in advance. - |
| Joseph
Registered User |
Mon Mar 03 15:29:46 CST 2008
Re:CWinThread::CreateThread
See below...
On Mon, 03 Mar 2008 20:57:49 GMT, no.address@sorry.com.zzz (Tom Sherren) wrote: QuoteQuestions regarding CWinThread::CreateThread **** Quote
So, for example, virtual CWinThread::InitInstance is called, so you would override this and put code here to initialize your thread. Then upon completion virtual CWinThread::ExitInstance is called, so you would override this to put code here to clean up. The rest of the time, CWinThread::Run would be running, and you would typically not override this; you would typically let the message pump to dispatch window and thread messages (it is not uncommon to create invisible top-level windows in a secondary thread to use them as message sinks; this is how SAPI and CAsyncSocket work, so you need UI threads for those purposes, at least). If you want the equivalent of a "worker thread" created by CWinThread::CreateThread, you typically put your thread loop in the InitInstance handler and return FALSE when the loop completes. joe **** Quote
Web: www.flounder.com">www.flounder.com MVP Tips: www.flounder.com/mvp_tips.htm">www.flounder.com/mvp_tips.htm - |
| AliR
Registered User |
Mon Mar 03 15:31:37 CST 2008
Re:CWinThread::CreateThread
1. Technically you should use AfxBeginThread to create and start any thread.
But if under some special circumstance you want to keep your thread object around and start it multiple times then I guess you can use CreateThread, which Creates a UI thread only. 2. The starting point of a UI thread is that InitInstance method. AliR. "Tom Sherren" <no.address@sorry.com.zzz>wrote in message QuoteQuestions regarding CWinThread::CreateThread - |
| Mark
Registered User |
Mon Mar 03 15:38:08 CST 2008
Re:CWinThread::CreateThread
"Tom Sherren" <no.address@sorry.com.zzz>wrote in message
QuoteQuestions regarding CWinThread::CreateThread will become a "UI" thread. Quote
CWinThread::m_pfnThreadProc member variable. CWinThread::m_pThreadParams sets the user data passed to the thread proc, and CWinThread::::m_bAutoDelete controls auto-deletion of the CWinThread object when the thread terminates. Mark -- Mark Salsbery Microsoft MVP - Visual C++ Quote
|
| Mark
Registered User |
Mon Mar 03 15:46:30 CST 2008
Re:CWinThread::CreateThread"Tom Sherren" <no.address@sorry.com.zzz>wrote in message QuoteQuestions regarding CWinThread::CreateThread I take that back - it starts a UI thread by default, but if you set the object's m_pfnThreadProc member before calling CreateThread() on the object, it will be a worker thread. Mark -- Mark Salsbery Microsoft MVP - Visual C++ Quote
|
| Mark
Registered User |
Mon Mar 03 15:54:01 CST 2008
Re:CWinThread::CreateThread
"Tom Sherren" <no.address@sorry.com.zzz>wrote in message
QuoteQuestions regarding CWinThread::CreateThread Annnnd....the thread proc started when you call CreateThread() is _AfxThreadEntry() (see the MFC source). _AfxThreadEntry() will branch to either m_pfnThreadProc if it's been initialized (worker) or to the Run() method (UI). I wonder how many more times it will take me to answer this somewhat correctly :-) Mark -- Mark Salsbery Microsoft MVP - Visual C++ Quote
|
| no
Registered User |
Mon Mar 03 17:13:05 CST 2008
Re:CWinThread::CreateThread
Thanks everyone for the useful responses.
Man, that was quick! - |
