sudhakar_koundinya
asked on
Catching the pointers of worker threads
Hello Friends,
To kill the threads I am using following code idea in my application. After killing the threads also, I am seeing some of the threads are still running in my application
CObArray threadArray;
UINT ExecThread(LPVOID lp)
{
int i=0,sum=0;
Sleep(10000);
for(i=0;i<1000;i++)
sum+=i;
CString str_sum;
str_sum.Format ("%d",sum);
AfxMessageBox("The sum is "+str_sum);
return 0;
}
void CTestKillThreadDlg::OnButt on1()
{
// TODO: Add your control notification handler code here
array.Add(AfxBeginThread(E xecThread, NULL,THREA D_PRIORITY _NORMAL+1) );
}
void CTestKillThreadDlg::OnButt on2()
{
// TODO: Add your control notification handler code here
try
{
CWinThread* thread=(CWinThread*)array. GetAt(0);
TerminateThread (thread->m_hThread ,0);
array.RemoveAt(0);
}catch(...)
{
array.RemoveAt(0);
// I put catch block here bcause, if a thread that i am accessing here is already executed, then
// TerminateThread (thread->m_hThread ,0); is raising exception, hence treating it as executed i am
// removing that thread from array
}
}
what is the problem in my codes??
Ad also I need to catch the pointers of all worker threads that are still in memory
thanks
sudhakar
To kill the threads I am using following code idea in my application. After killing the threads also, I am seeing some of the threads are still running in my application
CObArray threadArray;
UINT ExecThread(LPVOID lp)
{
int i=0,sum=0;
Sleep(10000);
for(i=0;i<1000;i++)
sum+=i;
CString str_sum;
str_sum.Format ("%d",sum);
AfxMessageBox("The sum is "+str_sum);
return 0;
}
void CTestKillThreadDlg::OnButt
{
// TODO: Add your control notification handler code here
array.Add(AfxBeginThread(E
}
void CTestKillThreadDlg::OnButt
{
// TODO: Add your control notification handler code here
try
{
CWinThread* thread=(CWinThread*)array.
TerminateThread (thread->m_hThread ,0);
array.RemoveAt(0);
}catch(...)
{
array.RemoveAt(0);
// I put catch block here bcause, if a thread that i am accessing here is already executed, then
// TerminateThread (thread->m_hThread ,0); is raising exception, hence treating it as executed i am
// removing that thread from array
}
}
what is the problem in my codes??
Ad also I need to catch the pointers of all worker threads that are still in memory
thanks
sudhakar
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.