有ThreadID的PostThreadMessage没有到达目

有ThreadID的PostThreadMessage没有到达目

本文介绍了具有ThreadID的PostThreadMessage没有到达目的地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的嵌入式应用程序正在显示一些实时值和一些滚动文本.
我正在使用CWinThread类来轮询我的comms端口并获取值,而主UI线程正在管理滚动.

我试图按特定的时间间隔进行轮询,并尝试使用计时器,但是除非我特别包含主UI HWND,否则它会被主UI类吞噬,并且无法到达目的地.主要的UI更新.

因此,我选择在通讯线程中使用PostThreadMessage来运行计时器,但是即使使用在线程创建时获取的threadID,我的消息也永远不会到达目的地.
我使用了IMPLEMENTMDECLARE _DYNAMIC,并声明了我的消息映射

 IMPLEMENT_DYNAMIC(CMyThread,CWinThread)

BEGIN_MESSAGE_MAP(CMyThread,CWinThread)
    //  ON_WM_TIMER()
    ON_MESSAGE(WM_APP + 15,OnTimer)
END_MESSAGE_MAP()

afx_msg  void  CADCValuesThread :: OnTimer(UINT nIDEvent)
{
    readComms();
}

无效 readComms()
{
    // 读取我的通讯端口
    :: PostThreadMessage(m_dwThreadID,WM_APP + 15, 0  0 );
} 



全部无济于事.

关于为何即使消息正在愉快地运行,我的消息仍未到达线程的任何帮助?

谢谢

Tony

解决方案



Hi,

My embedded application is displaying some real time values and some scrolling text.
I am using a CWinThread class to poll my comms port and get the values, and the main UI thread is managing the scrolling.

I am trying to poll at specific intervals, and have tried to use a timer, but this gets gobbled up by the main UI class and doesn''t reach the destination unless I specifically include the main UI HWND, which then causes a delay in the main UI update.

So, I chose to use PostThreadMessage in my comms thread to run my timer, but even using the threadID acquired at thread creation, my message never reaches the destination.
I have used IMPLEMENTM and DECLARE _DYNAMIC, and have declared my message maps

IMPLEMENT_DYNAMIC(CMyThread, CWinThread)

BEGIN_MESSAGE_MAP(CMyThread, CWinThread)
    //ON_WM_TIMER ( )
    ON_MESSAGE(WM_APP+15, OnTimer)
END_MESSAGE_MAP()

afx_msg void CADCValuesThread::OnTimer(UINT nIDEvent)
{
    readComms();
}

void readComms()
{
    //read my comms port
    ::PostThreadMessage(m_dwThreadID, WM_APP+15, 0, 0);
}



All to no avail.

Any help as to why my message is not reaching my thread, even though the thread is happily running?

Thanks

Tony

解决方案




这篇关于具有ThreadID的PostThreadMessage没有到达目的地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 06:56