The Updatedata, which calls the UI thread in the work thread, will cause Assert's issues and solutions.

xiaoxiao2021-03-06  41

Recently I have written a code, create a window in the UI thread, then modify some of the data in this window in the working thread, and then use Updatedata (false) to update the contents of the window, the result will appear below the debug version. Assert error, said the wrong place is the 888 rows and 889 lines of WinCore.cpp, that is, these two sentences.

Assert (P

=

PMAP

->

LookUppermanent (m_hwnd))

! =

NULL

||

(p

=

PMAP

->

LookupTemportPorary (m_hwnd))

! =

NULL); Assert ((CWND)

*

) P

==

THIS

);

//

Must be US

I didn't have much MFC, I was not familiar, turned over the task, in http://support.microsoft.com/default.aspx?scid=kb;n-us;147578 found an article, that is, the MFC window The problem of crossing thread is that the MFC window is thread is related, and each window is stored in the thread-local-storage (tls)), then I understand why I understand why I understand why I understand why I understand why? The two sentences will have an error, and the thread environments are all different. This article provides two modifications: one is to use fromHandle to get a CWND *, then call Updatedata, this I have no experiment success, the result is that although it is not reported, but the interface is not updated. The other is to transfer to the UI thread to the UI thread by sending a message. You can map a message, such as ON_MESSAGE (WM_UPDATA, ONUPDATA) ), Then use the sendMessage (WM_UPDATEDATA, FALSE) to send a message to the window, the message processing of the window is definitely in the UI thread, which can be used to update the interface, the experiment is successful, and Assert is eliminated.

Lresult CprotectPage :: Onupdatedata (WPARAM WPARAM, LPARAM LPARAM)

...

{Updatedata (wparam); return 0;}

Still a little doubt, just when I started to call Updatedata (false) in the working thread, although there is ASSERT error, the result is still correct, there is no impact, I don't know what this Assert does mean?

转载请注明原文地址:https://www.9cbs.com/read-75835.html

New Post(0)