Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Iam new to vc++. By using worker thread, iam try to send data(that can be read from the file) to view...,using UpdateAllViews().The debug assertion fails occursin updateallviews...if iam using function to send a data to view continuously with the help of worker thread...it works perfect...but iam using updateallviews means..,these error will be occured..(in DeBUG mode)..but in RELEASE mode..both r working fine..coming below is my sample code:


in Docclass
<u>FileReadDisplayDoc.h
</u>
unsigned long strTemp ;


<u>FileReadDisplayDoc.cpp</u>

CWinThread pThreadObj;

void CFileReadDisplayDoc::OnToolbarSelectFile()
{
//WithoutThreadSendData() ;//my functions
WithThreadSendData() ;//my functions
}

void CFileReadDisplayDoc::WithoutThreadSendData()
{
CString m_strFileName ;
char strRead[3] ;
FILE *fTP ;


char strFileFilter[] = {"TEXT FILES (*.TXT) |*.TXT| DOC FILES(*.DOC) |*.DOC|ALL Files(*.*)|*.*||"} ;
CFileDialog FileDlg(TRUE, ".BMD","", 0, strFileFilter) ;
if (FileDlg.DoModal()==IDOK)
{
m_strFileName = FileDlg.GetFileName() ;
fTP = fopen(m_strFileName, "r") ;

while(!feof(fTP))
{
unsigned long nDataVal = 0 ;
char *nStatus = NULL ;
fread(strRead,3,1,fTP) ;
strRead[2] = '\0' ;
nDataVal=strtoul(strRead, &nStatus, 10) ;
strTemp = (unsigned char)nDataVal ;
Sleep(100) ;
<b> UpdateAllViews(NULL,strTemp ,NULL) ;</b>
//here Debug assertion failed....in update all view...
//what's the solution for these type of problems...?if anyone..possible...,,?
//plz send correct code to my mail: t.r.yuva@gmail.com
<b>(or)</b>
yuvifun(strTrackData);//for without thread send data
//fun() to send data to view

}
fclose(fTP) ;
}
}

//my thread

UINT DataSendThread(LPVOID ptrTPThreadParam)
{ CFileReadDisplayDoc *pdocObj = (CFileReadDisplayDoc*) ptrTPThreadParam;
pdocObj->WithoutThreadSendData();

return 0;
}</u>


void CFileReadDisplayDoc::WithThreadSendData()
{
pThreadObj = AfxBeginThread(DataSendThread,this,THREAD_PRIORITY_LOWEST,0,CREATE_SUSPENDED,0) ;
pThreadObj->ResumeThread() ;
}

//in view.cpp

void CDisplay::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{

unsigned char strD[2] ;
CString getv ;

strD[0] = lHint ;
getv.Format("%d",strD[0]) ;
SetDlgItemText(IDE_DDISPLAY,getv) ;
}

What's the solution....for Debug assertion failed error occurs in line no : 888 wincrore.cpp (while debugging it occurs in Update All Views...
post solution to my mail : t.r.yuva@gmail.com
Posted

1 solution

Correctly using worker threads is tricky, please have a look at Joseph M. Newcomer's "Using Worker Threads" [^].
:)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900