worker thread did not survive the release version - MFC
-
worker thread did not survive the release version - MFC in the debug version it did not clash and ran smooth, and completed the cyclesequence function but it clashed badly in the release version. cyclesequence function was never completed sry i am very bad in threading. i have search all over but cannot find the solution ok here's how my program goes when the user presses a button called "RUN" , i begin my thread
void COpc_serialDlg::OnRun() { m_th_sequence = AfxBeginThread(th_start_sequence, (LPVOID)this ); m_run.EnableWindow(FALSE); }
my thread begins by obtaining information from editboxes and starts a function called CycleSequenceUINT COpc_serialDlg::th_start_sequence(LPVOID lpvParam) { COpc_serialDlg *th_start_receiving = (COpc_serialDlg*)lpvParam; // standard in thread int times = 0; CString startstring = ""; CString repeatstring = ""; CString endstring = ""; times = th_start_receiving->GetDlgItemInt(IDC_REPEAT_TIMES1); th_start_receiving->GetDlgItemText(IDC_STARTKEY1 , *startstring); th_start_receiving->GetDlgItemText(IDC_REPEAT1 , *repeatstring); th_start_receiving->GetDlgItemText(IDC_ENDKEY1 , *endstring); th_start_receiving->CycleSequence(times, *startstring, *repeatstring, *endstring); th_start_receiving->PrintRedDebugMsg( "Cycle thread exiting"); th_start_receiving->m_run.EnableWindow(TRUE); return 0; }
here's how CycleSequence function looks likeint COpc_serialDlg::CycleSequence(int times, CString startstring, CString repeatstring, CString endstring) { CString temp_string = ""; int i = 0; int Stroke_Count = GetNumberOfStrokes( startstring); CString local_repeatstring = ""; CString local_repeatstring2 = ""; // SetTimer(999 , 2000,0); // only when this timer expires, green light will come again, if red light is set again, timer resets // start string just write once before anything else for( i = 0 ; i < Stroke_Count ; i++) { local_repeatstring = startstring; m_serial.Write(Read_Out_Int(local_repeatstring),1,0,0,10); // 5000 ms timeout startstring = Remove_Out_Int(startstring); // let's wait 15 seconds for a response from OPC SetTimer( 999 , 15000 , NULL); WaitForSingleObject(m_idle_event , INFINITE); // after every .write command must contain this } // looping script is here Stroke_Count = GetNumberOfStrokes( repeatstring); for( i = 0 ; i < times ; i++) { local_repeatstring = repeatstring; for( int j = 0 ; j < Stroke_
-
worker thread did not survive the release version - MFC in the debug version it did not clash and ran smooth, and completed the cyclesequence function but it clashed badly in the release version. cyclesequence function was never completed sry i am very bad in threading. i have search all over but cannot find the solution ok here's how my program goes when the user presses a button called "RUN" , i begin my thread
void COpc_serialDlg::OnRun() { m_th_sequence = AfxBeginThread(th_start_sequence, (LPVOID)this ); m_run.EnableWindow(FALSE); }
my thread begins by obtaining information from editboxes and starts a function called CycleSequenceUINT COpc_serialDlg::th_start_sequence(LPVOID lpvParam) { COpc_serialDlg *th_start_receiving = (COpc_serialDlg*)lpvParam; // standard in thread int times = 0; CString startstring = ""; CString repeatstring = ""; CString endstring = ""; times = th_start_receiving->GetDlgItemInt(IDC_REPEAT_TIMES1); th_start_receiving->GetDlgItemText(IDC_STARTKEY1 , *startstring); th_start_receiving->GetDlgItemText(IDC_REPEAT1 , *repeatstring); th_start_receiving->GetDlgItemText(IDC_ENDKEY1 , *endstring); th_start_receiving->CycleSequence(times, *startstring, *repeatstring, *endstring); th_start_receiving->PrintRedDebugMsg( "Cycle thread exiting"); th_start_receiving->m_run.EnableWindow(TRUE); return 0; }
here's how CycleSequence function looks likeint COpc_serialDlg::CycleSequence(int times, CString startstring, CString repeatstring, CString endstring) { CString temp_string = ""; int i = 0; int Stroke_Count = GetNumberOfStrokes( startstring); CString local_repeatstring = ""; CString local_repeatstring2 = ""; // SetTimer(999 , 2000,0); // only when this timer expires, green light will come again, if red light is set again, timer resets // start string just write once before anything else for( i = 0 ; i < Stroke_Count ; i++) { local_repeatstring = startstring; m_serial.Write(Read_Out_Int(local_repeatstring),1,0,0,10); // 5000 ms timeout startstring = Remove_Out_Int(startstring); // let's wait 15 seconds for a response from OPC SetTimer( 999 , 15000 , NULL); WaitForSingleObject(m_idle_event , INFINITE); // after every .write command must contain this } // looping script is here Stroke_Count = GetNumberOfStrokes( repeatstring); for( i = 0 ; i < times ; i++) { local_repeatstring = repeatstring; for( int j = 0 ; j < Stroke_
-
worker thread did not survive the release version - MFC in the debug version it did not clash and ran smooth, and completed the cyclesequence function but it clashed badly in the release version. cyclesequence function was never completed sry i am very bad in threading. i have search all over but cannot find the solution ok here's how my program goes when the user presses a button called "RUN" , i begin my thread
void COpc_serialDlg::OnRun() { m_th_sequence = AfxBeginThread(th_start_sequence, (LPVOID)this ); m_run.EnableWindow(FALSE); }
my thread begins by obtaining information from editboxes and starts a function called CycleSequenceUINT COpc_serialDlg::th_start_sequence(LPVOID lpvParam) { COpc_serialDlg *th_start_receiving = (COpc_serialDlg*)lpvParam; // standard in thread int times = 0; CString startstring = ""; CString repeatstring = ""; CString endstring = ""; times = th_start_receiving->GetDlgItemInt(IDC_REPEAT_TIMES1); th_start_receiving->GetDlgItemText(IDC_STARTKEY1 , *startstring); th_start_receiving->GetDlgItemText(IDC_REPEAT1 , *repeatstring); th_start_receiving->GetDlgItemText(IDC_ENDKEY1 , *endstring); th_start_receiving->CycleSequence(times, *startstring, *repeatstring, *endstring); th_start_receiving->PrintRedDebugMsg( "Cycle thread exiting"); th_start_receiving->m_run.EnableWindow(TRUE); return 0; }
here's how CycleSequence function looks likeint COpc_serialDlg::CycleSequence(int times, CString startstring, CString repeatstring, CString endstring) { CString temp_string = ""; int i = 0; int Stroke_Count = GetNumberOfStrokes( startstring); CString local_repeatstring = ""; CString local_repeatstring2 = ""; // SetTimer(999 , 2000,0); // only when this timer expires, green light will come again, if red light is set again, timer resets // start string just write once before anything else for( i = 0 ; i < Stroke_Count ; i++) { local_repeatstring = startstring; m_serial.Write(Read_Out_Int(local_repeatstring),1,0,0,10); // 5000 ms timeout startstring = Remove_Out_Int(startstring); // let's wait 15 seconds for a response from OPC SetTimer( 999 , 15000 , NULL); WaitForSingleObject(m_idle_event , INFINITE); // after every .write command must contain this } // looping script is here Stroke_Count = GetNumberOfStrokes( repeatstring); for( i = 0 ; i < times ; i++) { local_repeatstring = repeatstring; for( int j = 0 ; j < Stroke_
awah wrote:
there are also other functions in CycleSequence like m_serial.Write , Remove_Out_Int and Read_Out_Int and GetNumberOfStrokes i did not include them here because i dont think they are causing the problem.
Not necessary. Its very difficult from seeing this code, to find out the problem. You can put down message boxes in code and narrow down the rpblem code. Additionally , refer this article by Joseph M. NewComer Joseph M. NewComer[^].
Prasad Notifier using ATL | Operator new[],delete[][^]
-
worker thread did not survive the release version - MFC in the debug version it did not clash and ran smooth, and completed the cyclesequence function but it clashed badly in the release version. cyclesequence function was never completed sry i am very bad in threading. i have search all over but cannot find the solution ok here's how my program goes when the user presses a button called "RUN" , i begin my thread
void COpc_serialDlg::OnRun() { m_th_sequence = AfxBeginThread(th_start_sequence, (LPVOID)this ); m_run.EnableWindow(FALSE); }
my thread begins by obtaining information from editboxes and starts a function called CycleSequenceUINT COpc_serialDlg::th_start_sequence(LPVOID lpvParam) { COpc_serialDlg *th_start_receiving = (COpc_serialDlg*)lpvParam; // standard in thread int times = 0; CString startstring = ""; CString repeatstring = ""; CString endstring = ""; times = th_start_receiving->GetDlgItemInt(IDC_REPEAT_TIMES1); th_start_receiving->GetDlgItemText(IDC_STARTKEY1 , *startstring); th_start_receiving->GetDlgItemText(IDC_REPEAT1 , *repeatstring); th_start_receiving->GetDlgItemText(IDC_ENDKEY1 , *endstring); th_start_receiving->CycleSequence(times, *startstring, *repeatstring, *endstring); th_start_receiving->PrintRedDebugMsg( "Cycle thread exiting"); th_start_receiving->m_run.EnableWindow(TRUE); return 0; }
here's how CycleSequence function looks likeint COpc_serialDlg::CycleSequence(int times, CString startstring, CString repeatstring, CString endstring) { CString temp_string = ""; int i = 0; int Stroke_Count = GetNumberOfStrokes( startstring); CString local_repeatstring = ""; CString local_repeatstring2 = ""; // SetTimer(999 , 2000,0); // only when this timer expires, green light will come again, if red light is set again, timer resets // start string just write once before anything else for( i = 0 ; i < Stroke_Count ; i++) { local_repeatstring = startstring; m_serial.Write(Read_Out_Int(local_repeatstring),1,0,0,10); // 5000 ms timeout startstring = Remove_Out_Int(startstring); // let's wait 15 seconds for a response from OPC SetTimer( 999 , 15000 , NULL); WaitForSingleObject(m_idle_event , INFINITE); // after every .write command must contain this } // looping script is here Stroke_Count = GetNumberOfStrokes( repeatstring); for( i = 0 ; i < times ; i++) { local_repeatstring = repeatstring; for( int j = 0 ; j < Stroke_
awah wrote:
my thread begins by obtaining information from editboxes
Well, this is a definite no-no from worker threads. Never touch the GUI from a worker thread, it may cause a deadlock. Read Joe Newcomer's article on the subject to get a better understanding of how to do worker threads here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown