Re: Crash when using listview.
Hi Charles,
thanks for the answer.
I understand that you encountered a crashing issue in your multi-threaded
application. You would like to know if there is a known Windows messaging
issue around your code.
If I have misunderstood, please let me know.
Yes, this is exactly it.
I could not find the cause of memory allocation issue, but I noticed that
you used SendMessage to send messages among your threads. This is not
recommended since it may cause deadlock in muti-threaded application. It is
recommended that you use PostThreadMessage to send messages among threads.
You may refer to this article:
Multiple Threads in the User Interface
http://msdn2.microsoft.com/en-us/library/ms810439.aspx
Regarding the dead locks, THREAD #2 and #3 can wait. It is not crucial
that they be handled right away, but we don't want to spam the message
queue of THREAD#4 with too many messages. So we use SendMessage in order
to receive a return value that will tell us if we can continue or not
the data processing.
THREAD #1 (Worker Thread)
Is sleeping waiting for THREAD #3 to finish. Is keeping no resource
locks needed by the other threads.
THREAD #2
Send a message to #4 in order to update an item in the list control
THREAD #3
Send a message to #4 in order to update an item in the list control
THREAD #4 (Main GUI Thread)
Is filling up a list control. The last call of this thread the SetItem
method of the CListControl in order to update an item of the list
control. The code looks like this:
==========
LVITEM lvi;
memset( &lvi, 0, sizeof(lvi) );
lvi.iItem = itemPosition;
// Setting the Subitem value (the rows' text)
for ( std::vector<Column*>::iterator columnIt = mColumns.begin();
columnIt != mColumns.end();
columnIt++ )
{
std::string columnValue = (*columnIt)->getValue( pBasicData ).c_str();
lvi.mask = LVIF_TEXT;
lvi.iSubItem = mHeader.OrderToIndex( (*columnIt)->getPosition() );
lvi.pszText = (LPSTR) columnValue.c_str();
SetItem( &lvi );
}
===========
We actually take a copy of the value in columnValue that is sent
afterward to the SetItem method. So I don't see where we could have
invalid memory in the deep core of SetItem.
THREAD #4 does not depend on resources locked by THREAD #1, #2, or #3,
so it should not dead lock.
So apart of the deadlocking possibility, is there other problems in
using SendMessage in different threads?
Thanks,
Pascal
Appreciate your understanding that this issue is memory related and
occurred intermittently which may need dump analysis to track the root
cause, however this work can only be done by Microsoft Customer Support
Services (CSS). We may give you some general suggestions here, but if they
do not help, effectively and immediately I recommend that you contact CSS
via telephone so that a dedicated Support Professional can assist you
recover the server in a more efficient manner. Please be advised that
contacting phone support will be a charged call.
To obtain the phone numbers for specific technology request please take a
look at the web site listed below.
http://support.microsoft.com/default.aspx?scid=fh;EN-US;PHONENUMBERS
If you are outside the US please see http://support.microsoft.com for
regional support phone numbers.
Best regards,
Charles Wang
Microsoft Online Community Support
=====================================================
Get notification to my posts through email? Please refer to:
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications
If you are using Outlook Express, please make sure you clear the check box
"Tools/Options/Read: Get 300 headers at a time" to see your reply promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
======================================================
When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================