0

I have created a UI thread. I m posting message to the UI thread which will write data in a file.

I am using PostThreadMessage API to post the message to User thread. My Problem is it's not writing all the data that I have posted. For Instance, if i post 100 data, it writes randomly 3 or 98 varies for every execution. The handler for Postdata is not getting called for every message.

CWriteToFile *m_pThread = (CWriteToFile *)AfxBeginThread(RUNTIME_CLASS (CWriteToFile));

PostThreadMessage(m_pThread->m_nThreadID , WM_WRITE_TO_FILE, (WPARAM)pData,NULL);

WaitForSingleObject(m_pThread, INFINITE);   

The Return value of PostThreadMessage is success.

Ajay
  • 18,086
  • 12
  • 59
  • 105
Karthik
  • 11
  • 3
  • Thanks for replying.. The return value of Post is success for all the posts. But handlers are called only for few messages. – Karthik Nov 25 '09 at 09:28

1 Answers1

0

The PostMessage family of functions can fail if the message queue is full. You should check whether or not the function call succeeds.

Yngve Hammersland
  • 1,634
  • 2
  • 14
  • 28