MFC Thread queue size
-
My application has several MFC threads running concurrently; these threads process their messages by using Peek Message. I want to know queue size in each thread (i.e. pending messages in thread queue).Is there any API that can tell me the message count or pending message count for each thread.? If there is no such an API, Is there any method to get message count at process level.?
ajmalsiddiqui
-
My application has several MFC threads running concurrently; these threads process their messages by using Peek Message. I want to know queue size in each thread (i.e. pending messages in thread queue).Is there any API that can tell me the message count or pending message count for each thread.? If there is no such an API, Is there any method to get message count at process level.?
ajmalsiddiqui
Would
GetQueueStatus()
help?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
Would
GetQueueStatus()
help?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
Thanks for the response , but i think this would not because this function returns the type of messages in the queue, not message count or queue length. I wan to get number of messages in queue or number of pending messages in queue.
ajmalsiddiqui
-
Thanks for the response , but i think this would not because this function returns the type of messages in the queue, not message count or queue length. I wan to get number of messages in queue or number of pending messages in queue.
ajmalsiddiqui
ajmalsiddiqi wrote:
Thanks for the response , but i think this would not because this function returns the type of messages in the queue, not message count or queue length.
It returns the number of the type you request.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
My application has several MFC threads running concurrently; these threads process their messages by using Peek Message. I want to know queue size in each thread (i.e. pending messages in thread queue).Is there any API that can tell me the message count or pending message count for each thread.? If there is no such an API, Is there any method to get message count at process level.?
ajmalsiddiqui
As far as I know you shouldn't run into any problems because the queue is too small. It's one of those questions that the very fact it's asked makes me wonder if your design is "correct". Can I ask why you need to know?
Steve
-
As far as I know you shouldn't run into any problems because the queue is too small. It's one of those questions that the very fact it's asked makes me wonder if your design is "correct". Can I ask why you need to know?
Steve
Thanks, I am little bit cofused by your reply and unable to understand.There is no issue I just want to add some functionality in my application threads, I just want to check queue length,In my application there are 15 threads one of them is main thread(Controller Thread).All threads are posting theire different customized message and some data in WPARAM/LPARAM using using PostThreadMessage function. Now the controller thread receive all these messages using PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)from thread mesage queue in its Run method. // code snap shot Controller::Run() { While(1) { while(PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)) { switch(pmsg ->message) { case MSG_RE_START: // log here pending messages in queue //do some functionality case MSG_RE_StOP: // log here pending messages in queue //do some functionality } PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE); } } } So when I receive one message I wan to log the pending messages which are still in queue and will be processed in next iteration means in call of PeekMessage. After Processing one Message I remove it from Thread queue using PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE) So can I get the queue status , how many number of messages are in thread queue or queue length.?
ajmalsiddiqui
-
Thanks, I am little bit cofused by your reply and unable to understand.There is no issue I just want to add some functionality in my application threads, I just want to check queue length,In my application there are 15 threads one of them is main thread(Controller Thread).All threads are posting theire different customized message and some data in WPARAM/LPARAM using using PostThreadMessage function. Now the controller thread receive all these messages using PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)from thread mesage queue in its Run method. // code snap shot Controller::Run() { While(1) { while(PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)) { switch(pmsg ->message) { case MSG_RE_START: // log here pending messages in queue //do some functionality case MSG_RE_StOP: // log here pending messages in queue //do some functionality } PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE); } } } So when I receive one message I wan to log the pending messages which are still in queue and will be processed in next iteration means in call of PeekMessage. After Processing one Message I remove it from Thread queue using PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE) So can I get the queue status , how many number of messages are in thread queue or queue length.?
ajmalsiddiqui
There are a number of issues here. The first problem you may encounter is related to the posting of thread messages. Does the main thread have any UI? Messages boxes, dialogs, anything like that? If so you may encounter the problem described here[^]. The solution (posting the messages to a hidden window instead) is also described. The next problem is that the main thread will sometimes throw away messages:
// code snap shot
Controller::Run()
{
While(1)
{
while(PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)) // -(1)
{
switch(pmsg ->message)
{
case MSG_RE_START:
// log here pending messages in queue
//do some functionality
case MSG_RE_StOP:
// log here pending messages in queue
//do some functionality
}
}PeekMessage(pmsg, NULL, 0, 0, PM\_REMOVE); // -(2) }
}
If there are no messages in the queue at point (1) but there is at point (2) the message is simply discarded. Another issue is that the main thread is constantly spinning in a busy loop doing nothing, degrading system performance. Also you simply discard all messages, even ones that don't belong to you. You should dispatch them. Also, even if your code was even close to working (which it's not) how do you know all the messages in the queue are yours?
Steve
-
There are a number of issues here. The first problem you may encounter is related to the posting of thread messages. Does the main thread have any UI? Messages boxes, dialogs, anything like that? If so you may encounter the problem described here[^]. The solution (posting the messages to a hidden window instead) is also described. The next problem is that the main thread will sometimes throw away messages:
// code snap shot
Controller::Run()
{
While(1)
{
while(PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)) // -(1)
{
switch(pmsg ->message)
{
case MSG_RE_START:
// log here pending messages in queue
//do some functionality
case MSG_RE_StOP:
// log here pending messages in queue
//do some functionality
}
}PeekMessage(pmsg, NULL, 0, 0, PM\_REMOVE); // -(2) }
}
If there are no messages in the queue at point (1) but there is at point (2) the message is simply discarded. Another issue is that the main thread is constantly spinning in a busy loop doing nothing, degrading system performance. Also you simply discard all messages, even ones that don't belong to you. You should dispatch them. Also, even if your code was even close to working (which it's not) how do you know all the messages in the queue are yours?
Steve
There is no UI thread all are worker threads.This was not the exact code , the exact code is running well there is no issue in the application.I just write the scenrio of my requirment. 1.If there is message in the queue it will be processed and then will be removed.So there is need little correction is code: PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE); // -(2) is inside the switch, not out of the inner while loop.
while(PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)) // -(1)
{
switch(pmsg ->message)
{
case MSG_RE_START:
// log here pending messages in queue
//do some functionality
break;
case MSG_RE_STOP:
// log here pending messages in queue
//do some functionality
break;
case MSG_RE_DATA:
// get number of pending messages
//Process data
break;}
PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE); // -(2)
}2.The main thread is not constantly spinning in a busy loop, becasue it waits on some events when exits from the inner loop.I did not mention, So leave it 3. Leave this, assume that the application is running not closing. I just want to know that How can i get the pending number of messages in queue , for example when i receive MSG_RE_DATA message,How many number of messages MSG_RE_DATA are pending.
ajmalsiddiqui
-
There is no UI thread all are worker threads.This was not the exact code , the exact code is running well there is no issue in the application.I just write the scenrio of my requirment. 1.If there is message in the queue it will be processed and then will be removed.So there is need little correction is code: PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE); // -(2) is inside the switch, not out of the inner while loop.
while(PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)) // -(1)
{
switch(pmsg ->message)
{
case MSG_RE_START:
// log here pending messages in queue
//do some functionality
break;
case MSG_RE_STOP:
// log here pending messages in queue
//do some functionality
break;
case MSG_RE_DATA:
// get number of pending messages
//Process data
break;}
PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE); // -(2)
}2.The main thread is not constantly spinning in a busy loop, becasue it waits on some events when exits from the inner loop.I did not mention, So leave it 3. Leave this, assume that the application is running not closing. I just want to know that How can i get the pending number of messages in queue , for example when i receive MSG_RE_DATA message,How many number of messages MSG_RE_DATA are pending.
ajmalsiddiqui
ajmalsiddiqi wrote:
while(PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)) // -(1) { switch(pmsg ->message) { case MSG_RE_START: // log here pending messages in queue //do some functionality break; case MSG_RE_STOP: // log here pending messages in queue //do some functionality break; case MSG_RE_DATA: // get number of pending messages //Process data break; } PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE); // -(2) }
In this code the
PeekMessage
is not "inside the switch", it's in thewhile
. Match up the brackets in the code you posted.Steve
-
ajmalsiddiqi wrote:
while(PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)) // -(1) { switch(pmsg ->message) { case MSG_RE_START: // log here pending messages in queue //do some functionality break; case MSG_RE_STOP: // log here pending messages in queue //do some functionality break; case MSG_RE_DATA: // get number of pending messages //Process data break; } PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE); // -(2) }
In this code the
PeekMessage
is not "inside the switch", it's in thewhile
. Match up the brackets in the code you posted.Steve
it must be inside the inner loop and out of the switch.
ajmalsiddiqui