Click to See Complete Forum and Search --> : terminating, susending/resuming thread ... a little complex issue (VC++)


UmairA
February 10th, 2006, 03:20 AM
The situation is that, I have created a worker thread that loads a COM dll and calls one of it function. The function is a blocking function.

Now I want to suspend/resume or termiante the worker thread while it is blocked in the function call.

I am using CreateThread and have tried TermiateThread, SuspendThread and ResumeThread but they seem to only execute after the thread has returned from the function call.

Is there a way to manage this blocked thread.

googler
February 10th, 2006, 08:19 AM
Can you show some code? Are you sure you're executing these functions on the correct thread at the correct time and from another thread? You need to have a handle to the worker thread.

UmairA
February 15th, 2006, 02:16 AM
Here is the code for creation of the thread:

BOOL CRunDlg::OnInitDialog()
{
CDialog::OnInitDialog();

if(!m_ifDialogCreated)
{
m_ifDialogCreated = TRUE;

// creating ISOGEN thread
m_param.parentID = GetSafeHwnd();
// m_workthread = AfxBeginThread(Execute, &m_param,THREAD_PRIORITY_NORMAL);
m_hThread = CreateThread(0,0,Execute,&m_param,0,&m_dwThreadID);
}
else
OnOK();

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}




Here is the code for Resume/Suspend and Kill thread :



void CRunDlg::OnBUTTONKill()
{
if(TerminateThread(m_hThread,1))
OnOK(); // close dialog
}

void CRunDlg::OnBUTTONSuspendOrResume()
{
static int state = 0;

if(state == 0)
{
GetDlgItem(IDC_STATIC_running)->ShowWindow(FALSE);
GetDlgItem(IDC_STATIC_suspended)->ShowWindow(TRUE);

SuspendThread(m_hThread);
state = 1;
}
else
{
GetDlgItem(IDC_STATIC_running)->ShowWindow(TRUE);
GetDlgItem(IDC_STATIC_suspended)->ShowWindow(FALSE);

ResumeThread(m_hThread);
state = 0;
}
}

kirants
February 15th, 2006, 11:47 AM
And what makes you think but they seem to only execute after the thread has returned from the function call. is happening ?

kirants
February 15th, 2006, 11:47 AM
Also, is the COM server an in-proc serevr or out-of-proc ?