VC: assert (pstate-> m_hsocketwindow! = NULL );
Csocket asserted error: assert (pstate-> m_hsocketwindow! = NULL );
Cause: When the socket is in the connection or sending status, it tries to close the socket, so it is interrupted at this asserted statement.
Cause analysis ::
Microsoft official explanation: http://support.microsoft.com/kb/140527/en-us
This assertion failure occurs because the csocket object was either created or accepted in the context of another thread. the socket Notification window was created in a different thread, and the m_hsocketwindow for the current thread is null, thus the assertion failure.
I understand that I use csocket across threads. The result is ....
Solution:
As already mentioned, a casyncsocket object shoshould be used only in the context of a single thread. if you need to switch the thread that is accessing a socket connection with another thread, then you shoshould use a separate casyncsocket object in each thread, and use the detach and attach functions to attach the casyncsocket object to the socket handle in the thread that is about to use the socket. use this sequence:
1.
Use detach () to detach the casyncsocket object from the socket handle in the thread that is currently using the casyncsocket object.
2.
Use attach () to attach a different casyncsocket object to the socket handle while in the context of the mfc ui thread in which you wish to begin accessing the socket connection.