cyberninja
March 9th, 2004, 05:01 PM
Question on PostThreadMessage()
When using PostThreadMessage(), I encounter a problem and do not know whether it is a bug or not.
Scenario:
Process 1:
1-1) create thread 1 to wait for WM_USER_TESTRESPONSE message
1-2) post WM_USER_TESTREQUEST message to thread 2.
Process 2:
2-1) create thread 2 to wait for WM_USER_TESTREQUEST message,
2-2) if WM_USER_TESTREQUEST is received,
2-3) post WM_USER_TESTRESPONSE to thread 1.
In testing, thread 2 can always receive WM_USER_TESTREQUEST, but when 2-3) happens, PostThreadMessage returns fail (Invalid thread id) and thread 1 will never receive it.
However, if I insert "Sleep(100)" between 2-2) and 2-3), PostThreadMessage will succeed and thread 1 will receive the response.
Is this an expected behaviour for PostThreadMessage()? If so, should I retry several times if PostThreadMessage() returns fail?
Thanks
cyberninja
When using PostThreadMessage(), I encounter a problem and do not know whether it is a bug or not.
Scenario:
Process 1:
1-1) create thread 1 to wait for WM_USER_TESTRESPONSE message
1-2) post WM_USER_TESTREQUEST message to thread 2.
Process 2:
2-1) create thread 2 to wait for WM_USER_TESTREQUEST message,
2-2) if WM_USER_TESTREQUEST is received,
2-3) post WM_USER_TESTRESPONSE to thread 1.
In testing, thread 2 can always receive WM_USER_TESTREQUEST, but when 2-3) happens, PostThreadMessage returns fail (Invalid thread id) and thread 1 will never receive it.
However, if I insert "Sleep(100)" between 2-2) and 2-3), PostThreadMessage will succeed and thread 1 will receive the response.
Is this an expected behaviour for PostThreadMessage()? If so, should I retry several times if PostThreadMessage() returns fail?
Thanks
cyberninja