Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to update data in a child thread in VC?

Status
Not open for further replies.

WalterGong

Programmer
Jul 19, 2002
1
CA
Dear sir:
I create two threads in my program and try to update data in the child thread with the function UpdateData(). When I run the program, I got a "Debug Assertion Failed" error.
The assertion is "ASSERT:):IsWindow(m_hWnd)); // calling UpdateData before DoModal?" in ...\Mfc\Src\Wincore.cpp.
The followings are my program:
UINT ChildThread(LPVOID param)
{
CCpu12Dlg aCpu12Dlg;
CString startPC=aCpu12Dlg.GetStartPC();

if( Interrupt == 0 )
{
aCpu12Dlg.m_lEdit_Time=111;
aCpu12Dlg.UpdateData(false); // Something is wrong here
}
return 0;
}//End of UINT ChildThread(LPVOID param)

void CCpu12Dlg::OnRun()
{
UpdateData(true);
runAddress=" "+m_sReg_PC+" ";
Interrupt = 0 ;
AfxBeginThread(ChildThread, NULL);
}//End of void CCpu12Dlg::OnRun()
Please tell me what the wrong with my program, thank you in advance.
Walter
 
You have it now: "ASSERT:):IsWindow(m_hWnd)); // calling UpdateData before DoModal?" in ...\Mfc\Src\Wincore.cpp.
You must start Dialog with DoModal() before You can use UpdateData().

 
Hi Walter,
Probably, what is happening is that the threads cannot see each other.
A safe way is to pass messages from one thread to another.Else you will always end up getting ASSERT failures like this.
You should use your own messages and write handlers for the same.Inside the handler , call the UpdateData function.
Refer MSDN for the article on how to communicate between threads.

Hope this helps.
Good Luck,

ss2905
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top