SendMessage problem ?????
-
Once all thread started from the main thread. I have put the follwing wait message in main thread to handle the child thread.Means until completed all the child threds Main thread must be wait. for that I had put. WaitForMultipleObjects(2, hThread, FALSE, INFINITE); will it stop the messagepumping ? because when thread reach at the following line .
SendMessage(hwndCmbProfile,CB_GETCURSEL,0,0);
The application does stop the working .In Task manger it shown application not responding. Is WaitForMultipleObjects affect on os message pumping?????? why the application get hang??"Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India
-
Once all thread started from the main thread. I have put the follwing wait message in main thread to handle the child thread.Means until completed all the child threds Main thread must be wait. for that I had put. WaitForMultipleObjects(2, hThread, FALSE, INFINITE); will it stop the messagepumping ? because when thread reach at the following line .
SendMessage(hwndCmbProfile,CB_GETCURSEL,0,0);
The application does stop the working .In Task manger it shown application not responding. Is WaitForMultipleObjects affect on os message pumping?????? why the application get hang??"Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India
amitmistry_petlad wrote:
will it stop the messagepumping ?
If you don't start any new thread, your application has only one thread. It means that if you do something that takes a lot of time, your application will not respond during this time, because the message loop is in the same thread. Thus, if you wait for something in the main thread, your application won't respond (unable to process messages) until the wait is terminated and until you are able to process messages once again.
Cédric Moonen Software developer
Charting control [v1.2] -
Once all thread started from the main thread. I have put the follwing wait message in main thread to handle the child thread.Means until completed all the child threds Main thread must be wait. for that I had put. WaitForMultipleObjects(2, hThread, FALSE, INFINITE); will it stop the messagepumping ? because when thread reach at the following line .
SendMessage(hwndCmbProfile,CB_GETCURSEL,0,0);
The application does stop the working .In Task manger it shown application not responding. Is WaitForMultipleObjects affect on os message pumping?????? why the application get hang??"Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India
Firstly this line looks funny:
WaitForMultipleObjects(2, hThread, FALSE, INFINITE);
If
hThread
is threadHANDLE
, as the Hungarian prefix suggests, then this should not compile. It looks like you're just waiting on oneHANDLE
. I'd guesshThread
is a pointer to an array ofHANDLE
s: if this is the case the "h" prefix is confusing and will throw programmers that are aware of Hungarian prefixes. Secondly, no message pump is running so theSendMessage
in the worker thread will (and should) block. What you need is theMsgWaitForMultipleObjects
function. Look in the ATL source code in the functionAtlWaitWithMessageLoop
for an example of its usage.Steve
-
Once all thread started from the main thread. I have put the follwing wait message in main thread to handle the child thread.Means until completed all the child threds Main thread must be wait. for that I had put. WaitForMultipleObjects(2, hThread, FALSE, INFINITE); will it stop the messagepumping ? because when thread reach at the following line .
SendMessage(hwndCmbProfile,CB_GETCURSEL,0,0);
The application does stop the working .In Task manger it shown application not responding. Is WaitForMultipleObjects affect on os message pumping?????? why the application get hang??"Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India
Messages sent to a window must be processed by the thread that created the window. When a worker thread calls
SendMessage()
, it blocks until the message handler returns. Since the message is going to a window (assuming it was created by the main thread, which is uaually the case), the thread that has to handle the message is blocked and can't run, so you've created a deadlock. You also have a bug in the call toWaitForMultipleObjects()
- you say you're passing 2 handles, but only providing one.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Dunder-Mifflin, this is Pam.
-
Messages sent to a window must be processed by the thread that created the window. When a worker thread calls
SendMessage()
, it blocks until the message handler returns. Since the message is going to a window (assuming it was created by the main thread, which is uaually the case), the thread that has to handle the message is blocked and can't run, so you've created a deadlock. You also have a bug in the call toWaitForMultipleObjects()
- you say you're passing 2 handles, but only providing one.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Dunder-Mifflin, this is Pam.
Thank you sir, How can I stop the deadlock situation? and child therad SendMessage to the window.
"Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India
-
Firstly this line looks funny:
WaitForMultipleObjects(2, hThread, FALSE, INFINITE);
If
hThread
is threadHANDLE
, as the Hungarian prefix suggests, then this should not compile. It looks like you're just waiting on oneHANDLE
. I'd guesshThread
is a pointer to an array ofHANDLE
s: if this is the case the "h" prefix is confusing and will throw programmers that are aware of Hungarian prefixes. Secondly, no message pump is running so theSendMessage
in the worker thread will (and should) block. What you need is theMsgWaitForMultipleObjects
function. Look in the ATL source code in the functionAtlWaitWithMessageLoop
for an example of its usage.Steve
Stephen Hewitt wrote:
I'd guess hThread is a pointer to an array of HANDLEs:
You are right sir , this is an array of HANDLES. Plese look at here sir,
for(...) { **hThread[i] = (HANDLE ) _beginthreadex(NULL, 0, &Thread, l, 0, &tid)**}
"Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India
-
Thank you sir, How can I stop the deadlock situation? and child therad SendMessage to the window.
"Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India
You should avoid the use of
SendMessage()
between threads; if the receiving thread is not processing messages your application will deadlock. UsePostMessage()
instead. Read more here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown -
You should avoid the use of
SendMessage()
between threads; if the receiving thread is not processing messages your application will deadlock. UsePostMessage()
instead. Read more here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknownGrate ! Thanks! But my Thread application passes through some function where I every next step ,I have used the GUI messaging so now how can i handle that situation. means fetching the values from the different control like combobox ,static text, listview during the thread is runing. But thank you very much, I will try it for PostMessage.
"Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India
-
Thank you sir, How can I stop the deadlock situation? and child therad SendMessage to the window.
"Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India
As Stephen suggested above,
AtlWaitWithMessageLoop()
is one way to have a thread wait and still be able to process messages. It's the method I use.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Dunder-Mifflin, this is Pam.
-
As Stephen suggested above,
AtlWaitWithMessageLoop()
is one way to have a thread wait and still be able to process messages. It's the method I use.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Dunder-Mifflin, this is Pam.
sir, I have found the help for that and I am satisfy with this answer but could you guide me where should i write this function? I mean in my Mainthread or the successive function call from the Mainthread.(:doh:) suppose , e.g.
for(....) { //thread created from here hThread[i]=(HANDLE ) _beginthreadex(NULL, 0, &Thread, l, 0, &tid); //calling from here ????:confused: }
here :confused: ????? where should I call and where should I defined ?unsigned __stdcall Thread(void* pArguments ) { HRESULT hr=NULL; struct argument_list *Lparam= (argument_list *)pArguments ; Package pkg; static int threadID; threadID++; { hr=pkg.EncodeMediaContent(Lparam->pszInFile,Lparam->pszOutFil,Lparam->hwndParent,Lparam->Host,Lparam->UserID,Lparam->InitPackageRequest,Lparam->ScriptFile,Lparam->Port,Lparam->hList,Lparam->_ProtectSet,Lparam->hWndinoutfiledir,Lparam->hwndEncrypt); } if(hr==S_OK) { MessageBox(0,L"thread gone finished" ,L"therad",0); _endthreadex( 0 ); } //or :confused: should I write some where here??? threadID--; return 0; }
"Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India