• Advertisement
Sign in to follow this  

[Win32 API] Message Priority

This topic is 3579 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
No, it isn't. This sounds you want to hack around another problem.

What is the actual problem you're facing? Too slow message processing? In that case, show your message loop.

Share this post


Link to post
Share on other sites
Hello,

I'm using the common message loop:


while(GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}



My problem is that when i create a dialog, I create two timers with it as well.

The two timer just spawns threads.

when I select the Menu, it seems to be waiting 'til whatever the threads wants to do is done with it. If the threads aren't finish yet, the Menu cant be selected (thus, I can't select the "Back" menu in my dialog box)

:(

Share this post


Link to post
Share on other sites
this is what the two timerprocs look like:



VOID CALLBACK TimerProcSockRead(HWND hWndDlg, UINT message, UINT iTimerID, DWORD dwTime) {
// Wait for the thread to finish
WaitForSingleObject(g_ThreadRead, INFINITE);

// Wait for the thread to finish
WaitForSingleObject(g_ThreadDispBMP, INFINITE);

// Decode & display received data
g_ThreadDispBMP = CreateThread(NULL,
0, (LPTHREAD_START_ROUTINE)ThreadDisplayBMP,
(LPVOID)NULL,
0, (LPDWORD)&g_ThreadDispBMPID);

}


VOID CALLBACK TimerProcDisplayBMP(HWND hWndDlg, UINT message, UINT iTimerID, DWORD dwTime) {
// Wait for the thread to finish
WaitForSingleObject(g_ThreadDispBMP, INFINITE);

// Wait for the thread to finish
WaitForSingleObject(g_ThreadRead, INFINITE);

// Read data from server
g_ThreadRead = CreateThread(NULL,
0, (LPTHREAD_START_ROUTINE)ThreadStreamRead,
(LPVOID)NULL,
0, (LPDWORD)&g_ThreadReadID);
}




They just create threads to call functions ThreadDisplayBMP and ThreadStreamRead.

This shouldn't block key inputs right? but it does for some reason...

(ThreadStreamRead reads data in from socket, it shouldn't block because it's in a thread)

Share this post


Link to post
Share on other sites
alright i solved it.

i replaced the WaitForSingleObject() functions with a boolean variable instead, checking if the boolean variable is true, then create the thread, if not, return from function.

Share this post


Link to post
Share on other sites
Your WM_TIMER message will be processed from DispatchMessage, and that'll call your callback, which blocks, causing your message loop to block.

If you're using a bool, make sure it's volatile. Although I'd recommend just using WaitForSingleObject() with a zero, or very small wait time. Certainly not INFINITE. WaitForSingleObject returns WAIT_TIMEOUT if it timed out, and WAIT_OBJECT_0 if the handles was signalled.

Share this post


Link to post
Share on other sites
@evil steve - i see, i had thought that when i use a callback for my timer, it'll be a separate thread, and won't need to go to the WM_TIMER in my dialog box. thanks!!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement