|
-
May 31st, 2005, 06:38 AM
#1
CreateThread
I do not understand why my program blocks when processing a long routine eventhough I use CreateThread...any clue??
m_hThread = CreateThread( 0,
0,
ThreadFunc,
(LPVOID)Param,
0,
&m_dwThreadID);
The ThreadFunc is accessed but my dialog remains blocked until the end of the process...
-
May 31st, 2005, 06:50 AM
#2
Re: CreateThread
Without seeing your full code me may won't find the problem. But use code tags when posting code!
-
May 31st, 2005, 06:59 AM
#3
Re: CreateThread
This is practically the whole thing I do to call this thread...from the main thread I call this funcion (funcA). Then I pass some parameters using Param.
Code:
HANDLE ThreadClass::funcA(BYTE node, WORD time)
{
DWORD Param;
Param =(6<<24)|(node<<16)|(time);
m_hThread = CreateThread (0,
0,
ThreadFunc,
(LPVOID)Param,
0,
&m_dwThreadID);
if(!m_hThread)
{
// Could not create thread
return false;
}
return m_hThread;
}
DWORD WINAPI ThreadClass::ThreadFunc(LPVOID pvParam)
{
BYTE func_nr = ((DWORD)pvParam>>24)&0xFF;
ThreadEventFlag = TRUE;
MathClass calc;
switch((BYTE)func_nr)
{
case 0:
...continue...
Last edited by rafraf; May 31st, 2005 at 07:07 AM.
-
May 31st, 2005, 07:14 AM
#4
Re: CreateThread
The calling code of where you call funcA might be more interesting. To see what happens after the thread was created.
Code Tags...
-
May 31st, 2005, 07:20 AM
#5
Re: CreateThread
here it goes
Code:
...
case ID_TH_SCAN_INJ:
{
ThreadClass thread;
int node = GetDlgItemInt(hDlg, IDC_COMBO_ELMB, NULL, NULL);
int time = GetDlgItemInt(hDlg, IDC_TH_SCAN_TIME, NULL, NULL); // in milliseconds
if(!thread.funcA(node, time))
MessageBox(NULL, "Thread Error (thread.funcA)", "WRONG PARAMETER", MB_ICONEXCLAMATION | MB_OK);
return TRUE;
}
break;
...
Last edited by rafraf; May 31st, 2005 at 07:34 AM.
-
May 31st, 2005, 07:47 AM
#6
Re: CreateThread
I have found that the problem comes out when I use this code (see below) inside my ThreadFunc.
g_hElmbDialog = handle of the dialog I call the thread.
If intead of calling CreateDialog using g_hElmbDialog, I use NULL, it works!!
boh??
Code:
g_hWaitBox = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_WAITBOX), g_hElmbDialog, (DLGPROC)About);
if(g_hWaitBox != NULL)
ShowWindow(g_hWaitBox, SW_SHOW);
else
MessageBox(g_hElmbDialog, "CreateDialog Returned NULL", "Warning!", MB_OK | MB_ICONINFORMATION);
Do you know why??
Last edited by rafraf; May 31st, 2005 at 07:56 AM.
-
May 31st, 2005, 08:04 AM
#7
Re: CreateThread
 Originally Posted by rafraf
I have found that the problem comes out when I use this code (see below) inside my ThreadFunc.
g_hElmbDialog = handle of the dialog I call the thread.
If intead of calling CreateDialog using g_hElmbDialog, I use NULL, it works!!
boh??
Code:
g_hWaitBox = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_WAITBOX), g_hElmbDialog, (DLGPROC)About);
if(g_hWaitBox != NULL)
ShowWindow(g_hWaitBox, SW_SHOW);
else
MessageBox(g_hElmbDialog, "CreateDialog Returned NULL", "Warning!", MB_OK | MB_ICONINFORMATION);
Do you know why??
Because if you show a dialog which is the child of another the parent window get's disabled until the child window has finished. This is the same behaviour as you would display a modal dialog > even if you are in another thread the parent window get's blocked until the child window gets closed.
You see why posting full code?
-
May 31st, 2005, 08:11 AM
#8
Re: CreateThread
Yes...That the parent window gets disabled I knew but that it gets blocked is something new for me... 
Thanks for your help!!!
-
May 31st, 2005, 08:25 AM
#9
Re: CreateThread
 Originally Posted by rafraf
Yes...That the parent window gets disabled I knew but that it gets blocked is something new for me...
Thanks for your help!!! 
You are welcome!
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
|