-
multithread problem
Why the following codes works first "for loop" and then "progressbar" but not parallerly?
Code:
void CProgressbarDlg::OnButton1()
{
hThread=AfxBeginThread(ThreadFunc,&m_Progress,THREAD_PRIORITY_HIGHEST);
for(int i=0;i<50000;i++)
{
m_edit=m_edit+"C";
UpdateData(FALSE);
}
// hThread->SuspendThread();
}
UINT ThreadFunc(LPVOID param1)
{
CProgressCtrl *param=(CProgressCtrl*)param1;
BOOL d=TRUE;
param->SetRange(1,10);
while(1)
{
if (d)
{
param->SetPos(param->GetPos()+1);
if (param->GetPos()==10)
d=FALSE;
}
else
{
param->SetPos(param->GetPos()-1);
if (param->GetPos()==1)
d=TRUE;
}
Sleep(500);
}
return 0;
}
-
Re: multithread problem
Read about MFC and multithreading. You can't reuse MFC objects across threads. It's simply not possible.
-
Re: multithread problem
I'm pretty sure I something like this before, and it worked fine.
Did you try changing the thread priotity from THREAD_PRIORITY_HIGHEST to THREAD_PRIORITY_NORMAL, and see what hapens ?
-
Re: multithread problem
Yes I tried it.
But if I create two more threds besides the base thred.
then the child threds work parallely.
But I am curious to know why do I need two more threds if I need only one more thred.
But in console programs it works fine.