Click here to Skip to main content
15,891,704 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: CFileDialog saving problem Pin
Naveen2-Aug-07 15:56
Naveen2-Aug-07 15:56 
GeneralRe: CFileDialog saving problem Pin
hxhl953-Aug-07 6:42
hxhl953-Aug-07 6:42 
GeneralRe: CFileDialog saving problem Pin
Naveen3-Aug-07 14:56
Naveen3-Aug-07 14:56 
AnswerRe: CFileDialog saving problem Pin
David Crow3-Aug-07 4:02
David Crow3-Aug-07 4:02 
QuestionFont Dialog Box? Setting the font? Pin
deostroll2-Aug-07 13:07
deostroll2-Aug-07 13:07 
AnswerRe: Font Dialog Box? Setting the font? Pin
Michael Dunn2-Aug-07 13:56
sitebuilderMichael Dunn2-Aug-07 13:56 
AnswerRe: Font Dialog Box? Setting the font? Pin
Mark Salsbery2-Aug-07 13:56
Mark Salsbery2-Aug-07 13:56 
Questionhaving problem terminating a thread Pin
alberthyc2-Aug-07 8:49
alberthyc2-Aug-07 8:49 
hi, i wrote a mfc dialog that's running a worker thread i want to terminate it from outside.

in CMyTestDlg: public CDialog{
static bool STOP;//a shared variable to signal the thread function
static UINT __cdecl Start();
CWinThread* pThread
....
in the cpp file, i have a OnBnClickedButtonStart() and OnBnClickedButtonStop()function to start and stop the thread
bool CMyTestDlg::Stop=false;

void CMyTestDlg::OnBnClickedButtonStart(){
pThread=AfxBeginThread(Start,this,-1,0,CREATE_SUSPENDED);
pThread->m_bAutoDelete=FALSE;
pThread->ResumeThread();
}

void CMyTestDlg::OnBnClickedButtonStop()
{
STOP=true;
if(::WaitForSingleObject(pThread->m_hThread,2000)==WAIT_OBJECT_0){
delete pThread;
m_ListBox_MSG.AddString(_T("Thread terminated succesfully"));
//message showed in a list box
}
else{
::TerminateThread(pThread->m_hThread,0);
m_ListBox_MSG.AddString(_T("Thread is not normally terminated!"));
//message showed in a list box
}
}

UINT __cdecl CMyTestDlg::Start(LPVOID pParam){

CMyTestDlg* me=(CMyTestDlg*)pParam;
while(STOP==false){
//looping here...

}
return 0;
}



when i stop the thread, from the message showed in the listbox, i found that the thread is always terminated "dangeroursly" which means the ::TerminateThread()function ran.

What could be the possible cause?








QuestionRe: having problem terminating a thread Pin
Mark Salsbery2-Aug-07 8:55
Mark Salsbery2-Aug-07 8:55 
AnswerRe: having problem terminating a thread Pin
alberthyc2-Aug-07 9:01
alberthyc2-Aug-07 9:01 
AnswerRe: having problem terminating a thread Pin
alberthyc2-Aug-07 9:15
alberthyc2-Aug-07 9:15 
GeneralRe: having problem terminating a thread Pin
Mark Salsbery2-Aug-07 10:14
Mark Salsbery2-Aug-07 10:14 
GeneralRe: having problem terminating a thread Pin
alberthyc2-Aug-07 10:21
alberthyc2-Aug-07 10:21 
AnswerRe: having problem terminating a thread Pin
led mike2-Aug-07 9:17
led mike2-Aug-07 9:17 
GeneralRe: having problem terminating a thread Pin
alberthyc2-Aug-07 9:20
alberthyc2-Aug-07 9:20 
GeneralRe: having problem terminating a thread Pin
led mike2-Aug-07 9:24
led mike2-Aug-07 9:24 
GeneralRe: having problem terminating a thread Pin
Mark Salsbery2-Aug-07 10:15
Mark Salsbery2-Aug-07 10:15 
AnswerRe: having problem terminating a thread Pin
Tony Hill2-Aug-07 9:30
mveTony Hill2-Aug-07 9:30 
GeneralRe: having problem terminating a thread Pin
alberthyc2-Aug-07 9:51
alberthyc2-Aug-07 9:51 
GeneralRe: having problem terminating a thread Pin
Randor 2-Aug-07 10:33
professional Randor 2-Aug-07 10:33 
GeneralRe: having problem terminating a thread Pin
alberthyc2-Aug-07 10:47
alberthyc2-Aug-07 10:47 
GeneralRe: having problem terminating a thread Pin
led mike2-Aug-07 10:49
led mike2-Aug-07 10:49 
GeneralRe: having problem terminating a thread Pin
Mark Salsbery2-Aug-07 10:56
Mark Salsbery2-Aug-07 10:56 
GeneralRe: having problem terminating a thread Pin
led mike2-Aug-07 11:01
led mike2-Aug-07 11:01 
GeneralRe: having problem terminating a thread Pin
alberthyc2-Aug-07 11:09
alberthyc2-Aug-07 11:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.