PostThreadMessage 失败
我创建了一个 UI 线程。我正在向 UI 线程发布消息,该线程会将数据写入文件。
我正在使用 PostThreadMessage
API 将消息发布到用户线程。我的问题是它没有写出我发布的所有数据。例如,如果我发布 100 个数据,它会为每次执行随机写入 3 或 98 个变量。并不是每条消息都会调用 Postdata 的处理程序。
CWriteToFile *m_pThread = (CWriteToFile *)AfxBeginThread(RUNTIME_CLASS (CWriteToFile));
PostThreadMessage(m_pThread->m_nThreadID , WM_WRITE_TO_FILE, (WPARAM)pData,NULL);
WaitForSingleObject(m_pThread, INFINITE);
PostThreadMessage
的返回值为成功。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果消息队列已满,PostMessage 系列函数可能失败。您应该检查函数调用是否成功。
The PostMessage family of functions can fail if the message queue is full. You should check whether or not the function call succeeds.