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

C / C++ / MFC

 
AnswerRe: Doubt in using SendInput function Pin
Syamlal S Nair15-Mar-07 18:37
Syamlal S Nair15-Mar-07 18:37 
GeneralRe: Doubt in using SendInput function Pin
prasad_som15-Mar-07 18:46
prasad_som15-Mar-07 18:46 
QuestionHow to judge if the folder can be written? Pin
Syouki_kou28-Feb-07 15:53
Syouki_kou28-Feb-07 15:53 
AnswerRe: How to judge if the folder can be written? Pin
Mark Salsbery28-Feb-07 16:14
Mark Salsbery28-Feb-07 16:14 
GeneralRe: How to judge if the folder can be written? Pin
Syouki_kou28-Feb-07 16:22
Syouki_kou28-Feb-07 16:22 
GeneralRe: How to judge if the folder can be written? Pin
Mark Salsbery28-Feb-07 16:51
Mark Salsbery28-Feb-07 16:51 
QuestionHow to send a scroll message to MS WORD? Pin
Michael ZY28-Feb-07 15:52
Michael ZY28-Feb-07 15:52 
Questionworker thread did not survive the release version - MFC Pin
awah28-Feb-07 15:34
awah28-Feb-07 15:34 
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() <br />
{	<br />
	m_th_sequence =	AfxBeginThread(th_start_sequence, (LPVOID)this );<br />
	m_run.EnableWindow(FALSE);<br />
	<br />
}<br />


my thread begins by obtaining information from editboxes and starts a function called CycleSequence
<br />
UINT COpc_serialDlg::th_start_sequence(LPVOID lpvParam)<br />
{<br />
    COpc_serialDlg *th_start_receiving = (COpc_serialDlg*)lpvParam; // standard in thread<br />
	int times = 0;<br />
	CString startstring = "";<br />
	CString repeatstring = "";<br />
	CString endstring = "";<br />
	times = th_start_receiving->GetDlgItemInt(IDC_REPEAT_TIMES1);<br />
	th_start_receiving->GetDlgItemText(IDC_STARTKEY1 , *startstring);<br />
	th_start_receiving->GetDlgItemText(IDC_REPEAT1 , *repeatstring);<br />
	th_start_receiving->GetDlgItemText(IDC_ENDKEY1 , *endstring);<br />
	th_start_receiving->CycleSequence(times, *startstring, *repeatstring, *endstring);<br />
	th_start_receiving->PrintRedDebugMsg( "Cycle thread exiting");<br />
	th_start_receiving->m_run.EnableWindow(TRUE);<br />
<br />
	return 0;<br />
}<br />




here's how CycleSequence function looks like

int COpc_serialDlg::CycleSequence(int times, CString startstring, CString repeatstring, CString endstring)<br />
{<br />
<br />
	CString temp_string = "";<br />
	int i = 0;<br />
	int Stroke_Count = GetNumberOfStrokes( startstring);<br />
	CString local_repeatstring = "";<br />
	CString local_repeatstring2 = "";<br />
<br />
//	SetTimer(999 , 2000,0); // only when this timer expires, green light will come again,  if red light is set again, timer resets<br />
<br />
<br />
// start string just write once before anything else		<br />
	for(  i = 0 ; i < Stroke_Count ; i++)<br />
	{<br />
<br />
		local_repeatstring = startstring;<br />
<br />
<br />
		m_serial.Write(Read_Out_Int(local_repeatstring),1,0,0,10);  // 5000 ms timeout<br />
		startstring = Remove_Out_Int(startstring);<br />
<br />
	// let's wait 15 seconds for a response from OPC<br />
		SetTimer( 999 , 15000 , NULL);<br />
		WaitForSingleObject(m_idle_event , INFINITE); // after every .write command must contain this<br />
<br />
	}<br />
<br />
// looping script is here<br />
	Stroke_Count = GetNumberOfStrokes( repeatstring);<br />
	for(  i = 0 ; i < times ; i++)<br />
	{<br />
		local_repeatstring = repeatstring;<br />
			for( int j = 0 ; j < Stroke_Count ; j++)<br />
			{<br />
				local_repeatstring2 = local_repeatstring;<br />
				ResetEvent(m_idle_event); // set it to non signal state ( red light )			<br />
				<br />
<br />
				PrintRedDebugMsg( "Waiting done");<br />
				m_serial.Write(Read_Out_Int(local_repeatstring2),1,0,0,10);  // 5000 ms timeout<br />
				local_repeatstring = Remove_Out_Int(local_repeatstring);<br />
<br />
		// let's wait 15 seconds for a response from OPC<br />
				SetTimer( 999 , 15000 , NULL);<br />
				WaitForSingleObject(m_idle_event , INFINITE); // after every .write command must contain this<br />
<br />
			}<br />
	}<br />
<br />
// ending script is here<br />
		Stroke_Count = GetNumberOfStrokes( endstring);<br />
<br />
<br />
<br />
	for(  i = 0 ; i < Stroke_Count ; i++)<br />
	{<br />
<br />
		local_repeatstring = endstring;<br />
<br />
<br />
		m_serial.Write(Read_Out_Int(local_repeatstring),1,0,0,10);  // 5000 ms timeout<br />
		startstring = Remove_Out_Int(startstring);<br />
<br />
		// let's wait 15 seconds for a response from OPC<br />
		SetTimer( 999 , 15000 , NULL);<br />
		WaitForSingleObject(m_idle_event , INFINITE); // after every .write command must contain this<br />
<br />
	}<br />
	PrintRedDebugMsg( "End of cycle reached");<br />
	return 0;<br />
}



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.

i believe the problem is the way i initalize stuff in cyclesequence and the way i do my loops

using:
- winxp
- VC++ 6.0
- MFC
AnswerRe: worker thread did not survive the release version - MFC Pin
Xing Chen28-Feb-07 15:52
Xing Chen28-Feb-07 15:52 
AnswerRe: worker thread did not survive the release version - MFC Pin
prasad_som28-Feb-07 17:56
prasad_som28-Feb-07 17:56 
AnswerRe: worker thread did not survive the release version - MFC Pin
Roger Stoltz28-Feb-07 21:20
Roger Stoltz28-Feb-07 21:20 
QuestionVseDebug with Visual express 2005 Pin
ForNow28-Feb-07 15:21
ForNow28-Feb-07 15:21 
Questionvector <t_vertice> puntos; [modified] Pin
George Lam28-Feb-07 15:02
George Lam28-Feb-07 15:02 
QuestionRe: vector t_vertice puntos; Pin
prasad_som28-Feb-07 17:29
prasad_som28-Feb-07 17:29 
GeneralRe: vector puntos; Pin
prasad_som28-Feb-07 18:15
prasad_som28-Feb-07 18:15 
GeneralRe: vector puntos; Pin
George Lam1-Mar-07 7:11
George Lam1-Mar-07 7:11 
AnswerRe: vector puntos; [modified] Pin
Mark Salsbery1-Mar-07 8:25
Mark Salsbery1-Mar-07 8:25 
Questionhelp on window on be set in always actvie ? Pin
icemelt(newbie)28-Feb-07 15:00
icemelt(newbie)28-Feb-07 15:00 
AnswerRe: help on window on be set in always actvie ? Pin
Xing Chen28-Feb-07 16:07
Xing Chen28-Feb-07 16:07 
GeneralRe: help on window on be set in always actvie ? Pin
icemelt(newbie)28-Feb-07 17:23
icemelt(newbie)28-Feb-07 17:23 
GeneralRe: help on window on be set in always actvie ? Pin
Xing Chen28-Feb-07 17:32
Xing Chen28-Feb-07 17:32 
QuestionScreen Fails to Refresh after another Pgm Paints Pin
syscwl28-Feb-07 13:56
syscwl28-Feb-07 13:56 
QuestionRe: Screen Fails to Refresh after another Pgm Paints Pin
Mark Salsbery28-Feb-07 14:12
Mark Salsbery28-Feb-07 14:12 
AnswerRe: Screen Fails to Refresh after another Pgm Paints Pin
syscwl28-Feb-07 14:52
syscwl28-Feb-07 14:52 
GeneralRe: Screen Fails to Refresh after another Pgm Paints Pin
Mark Salsbery28-Feb-07 15:04
Mark Salsbery28-Feb-07 15:04 

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.