|
-
May 12th, 2005, 08:27 AM
#1
Thread Starter
Addicted Member
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;
}
-
May 12th, 2005, 12:54 PM
#2
Re: multithread problem
Read about MFC and multithreading. You can't reuse MFC objects across threads. It's simply not possible.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 12th, 2005, 03:52 PM
#3
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 ?
-
May 13th, 2005, 12:59 AM
#4
Thread Starter
Addicted Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|