MFC worker thread and message Queues
-
Hi, When I’m not using MFC and starting worker threads with _beginthreadex I can give them message queues by calling: PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); and then later on in the thread use GetMessage. I can do this without a window which is pretty cool. I tried putting PeekMessage into the ThreadFunc of a CWinThread derived class but it fails and, of course, the later call to GetMessage causes the program to hang. Before I start pounding my head against the wall I figured I would ask here to see if anybody would know why this would fail and if it is possible to workaround (without creating a window and using a UI thread). Thanks, -Kevin
-
Hi, When I’m not using MFC and starting worker threads with _beginthreadex I can give them message queues by calling: PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); and then later on in the thread use GetMessage. I can do this without a window which is pretty cool. I tried putting PeekMessage into the ThreadFunc of a CWinThread derived class but it fails and, of course, the later call to GetMessage causes the program to hang. Before I start pounding my head against the wall I figured I would ask here to see if anybody would know why this would fail and if it is possible to workaround (without creating a window and using a UI thread). Thanks, -Kevin
GetMessage will hang if you don't have a message waiting. Are you using PostThreadMessage to post a message to that thread? If so, make sure you are doing that properly. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
-
GetMessage will hang if you don't have a message waiting. Are you using PostThreadMessage to post a message to that thread? If so, make sure you are doing that properly. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
Tim, I’ve been writing server apps w/o a GUI so bear with me on my next question. Why would the GUI hang if a message queue has been created on an independent worker thread? I’m beginning to believe that a queue has not been created because the call to PeekMessage returns FALSE. -Kevin
-
Tim, I’ve been writing server apps w/o a GUI so bear with me on my next question. Why would the GUI hang if a message queue has been created on an independent worker thread? I’m beginning to believe that a queue has not been created because the call to PeekMessage returns FALSE. -Kevin
I figured out why the GUI was hanging. A mistake not related to the Message Queue. But I still can't get the Message Q to work. Is there any reason why the scheme in my first post would not work? Is the thread ID that I get from the CWinThread valid to use in: PostThreadMessage(pThread->m_nThreadID, 1,1,1); :confused: Thanks, Kevin
-
I figured out why the GUI was hanging. A mistake not related to the Message Queue. But I still can't get the Message Q to work. Is there any reason why the scheme in my first post would not work? Is the thread ID that I get from the CWinThread valid to use in: PostThreadMessage(pThread->m_nThreadID, 1,1,1); :confused: Thanks, Kevin
Without more example code, I have no idea. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
-
Hi, When I’m not using MFC and starting worker threads with _beginthreadex I can give them message queues by calling: PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); and then later on in the thread use GetMessage. I can do this without a window which is pretty cool. I tried putting PeekMessage into the ThreadFunc of a CWinThread derived class but it fails and, of course, the later call to GetMessage causes the program to hang. Before I start pounding my head against the wall I figured I would ask here to see if anybody would know why this would fail and if it is possible to workaround (without creating a window and using a UI thread). Thanks, -Kevin
I gave up on trying to create a message queue in an MFC worker thread by calling PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); There is a good article by Joseph M. Newcomer titled "Using User-Interface Threads" which describes what I wanted to do using UI Threads. I still would like to know why i can't create the message queue, though! -Kevin