MFC StringArray add出错

图片说明
KERNELBASE! 769522a1()
_CrtDbgReport(int 2, const char * 0x1024e184 string', int 1017, const char * 0x00000000, const char * 0x1024e080string') line 353
_free_dbg_lk(void * 0x01f45f20, int 1) line 1017 + 74 bytes
_free_dbg(void * 0x01f45f20, int 1) line 970 + 13 bytes
operator delete(void * 0x01f45f20) line 351 + 12 bytes
CStringArray::SetSize(int 34, int -1) line 167 + 18 bytes
CStringArray::SetAtGrow(int 33, const CString & {"输出通道3连接中断..."}) line 243
CStringArray::Add(const CString & {"输出通道3连接中断..."}) line 247
ShowAndWriteAlarmInfo(CString & {"输出通道3连接中断..."}) line 200
CIoCnt::SetIconState(int 0) line 301 + 9 bytes
CNetTcpCnt::ReConnect() line 202 + 21 bytes
CIoCnt::ReConnect() line 261
CIoCnt::Send(char * 0x07b2edd0, int 2000) line 242
CIoCnt::DoData() line 106 + 22 bytes
CSendThread::SingleStep() line 69 + 19 bytes
CXThread::InitInstance() line 69 + 16 bytes
CSendThread::InitInstance() line 40
_AfxThreadEntry(void * 0x0018ef18) line 116 + 13 bytes
_threadstartex(void * 0x01f40da0) line 212 + 13 bytes
KERNEL32! 762933ca()
NTDLL! 77b19ed2()
NTDLL! 77b19ea5()

程序多次调用下面函数,前面没出错,后面调用时执行到Add()程序崩溃了
StringArray _LogStrAry;

void ShowAndWriteAlarmInfo(CString &AlarmInfo)
{
CString temp;
int nSize = _LogStrAry.GetSize() ;
if (nSize > 50) //多于50条就扔掉
{
/// modified by tim 2006.09.07 for 删除数组中数据时,必须防止和写log的线程冲突
//_LogStrAry.RemoveAll() ;
_LogCritical.Lock() ;
_LogStrAry.RemoveAll() ;
_LogCritical.Unlock() ;
//// end
}

temp.Empty();
temp =AlarmInfo;
_LogStrAry.Add(temp) ;     //将报警信息装入报警序列中

}

http://blog.sina.com.cn/s/blog_635ff3050102ux8g.html

在一个线程中,简单的使用add,RemoveAt不会出问题,但在多线程中,有的要add, 有的要RemoveAt,就会出问题