Click to See Complete Forum and Search --> : Thread problem
wangwangwangwang
December 2nd, 2004, 03:03 AM
Hi all,
i have two dialogs:A,B
A create B and Start a thread ("thread A")in A, then hide itself and show the B,but the thread A is running background.
In the B, It also will start a thread("thread B").
i met a problem: if thread A enter a function that will need heavy calculation,the
thread B will seems be hung up until the thread A returned from the function.
so the thread B didn't work smoothly, that's not i want,
what should i do?
i just want the thread B worked smoothly
gstercken
December 2nd, 2004, 03:23 AM
i have two dialogs:A,B
A create B and Start a thread ("thread A")in A, then hide itself and show the B,but the thread A is running background. In the B, It also will start a thread("thread B").
i met a problem: if thread A enter a function that will need heavy calculation,the
thread B will seems be hung up until the thread A returned from the function.You'll probably need to post some code to clarify your post. For example, it is unclear what you mean by "Start a thread in A" - are you talking about a worker thread or a UI thread? Moreover, are your dialogs modal or modeless? Finallly, are you using MFC or Win32 API?
cilu
December 2nd, 2004, 03:25 AM
Moreover, do the thread have the same priority?
Andreas Masur
December 2nd, 2004, 04:36 AM
[ Moved thread ]
wangwangwangwang
December 2nd, 2004, 04:44 AM
You'll probably need to post some code to clarify your post. For example, it is unclear what you mean by "Start a thread in A" - are you talking about a worker thread or a UI thread? Moreover, are your dialogs modal or modeless? Finallly, are you using MFC or Win32 API?
Thread is work thread, dialog is modeless dialog, using MFC,use CreateThread
to create the thread,and the function that the Thread A call is in a dll
, the Priority is the same between them.
just now i reduce the Priority of the Thread A and add the Priority of Thread B,
it seems that something is improved. but it is still not smoothly.
thank you
gstercken
December 2nd, 2004, 04:49 AM
Sorry, but it's still unclear what happens in your scenario. How is the second dialog created, and from where (which function) are you creating the worker threads? And what do you mean by "thread B didn't work smoothly" - how are you observing that? Is the thread responsible for any output in one of the dialogs? If yes, how are you producing that output? I still think it would be best if you posted your relevant code (please use code tags if you do).
wangwangwangwang
December 2nd, 2004, 05:05 AM
Sorry, but it's still unclear what happens in your scenario. How is the second dialog created, and from where (which function) are you creating the worker threads? And what do you mean by "thread B didn't work smoothly" - how are you observing that? Is the thread responsible for any output in one of the dialogs? If yes, how are you producing that output? I still think it would be best if you posted your relevant code (please use code tags if you do).
thank you for your reply
////////////////////////////////////////////////////////
{
if (m_PrintEndDlg==NULL || !m_PrintEndDlg->GetSafeHwnd())
{
m_PrintEndDlg = new CPrintEndDlg(this);
m_PrintEndDlg->Create(IDD_WIZARD_PRINTEND, this);
}
m_PrintEndDlg->ShowWindow(SW_SHOW);
ShowWindow(SW_HIDE);
DWORD id;
//create the Thread A
m_hPrintThread = CreateThread(0,0,PrinttingThread,this,0,&id);
SetThreadPriority(m_hPrintThread,THREAD_PRIORITY_LOWEST);
//Tell the Dialog B to Create the Thread B
m_PrintEndDlg->PostMessage(WM_PRINT_BEGIN);
}
///////////////////////////////////////////////////////
//Dialog B , to Create the Thread B
if (message == WM_PRINT_BEGIN)
{
DWORD id;
HANDLE hd = CreateThread(0,0,ShowSendingThread,this,0,&id);
}
//////////////////////////////////////
In Thread A ,it will call a function in the DLL, the function will have heavy caculation in it.
Thread B just show a string in the Dialog B and twinkle it, at first time i use the timer, it is the same problem occurs,so i try the thread mode,but the result is same.
thanks
gstercken
December 2nd, 2004, 05:53 AM
And where are the code tags?
Andreas Masur
December 2nd, 2004, 07:05 AM
And where are the code tags?
Here they are... :D
gstercken
December 2nd, 2004, 07:26 AM
Here they are... :DThanks, Andreas. :)
@wangwangwangwang: That code snippet doesn't show at all what might be wrong. It lacks the information from which function you are calling CreateThread about the implementation of PrinttingThread() about the implementation of ShowSendingThread() how thread B shows the string (twinkles?) it in the dialog.It's also still unclear from what you conclude that the thread is not "working smoothly". I also don't understand why you need two worker threads here - wouldn't one have been enough?
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.