Re: Batch file and MFC (Properly Terminating Application)
- From: "one-trick-pony" <worldofpain.aamir@xxxxxxxxx>
- Date: 5 Feb 2007 13:47:36 -0800
Thanks Scott-
afx_msg LRESULT OnDummyMsg(WPARAM wParam, LPARAM lParam );
I wanted to keep things simple by not using any input parameters but
shortcuts can be dangerous. I have a working program with thread that
is using Joseph's code for thread creation. Now next issue, I am
working on terminating threads. Once thread is spun off and main gui
is sitting and waiting for thread to finish, user clicks Exit on main
GUI thread. I would like to keep things simple by not using exception
just yet as suggested by Joseph.
The thread code must be designed to always detect a shutdown signal.
Below is skeleton of the thread code;
UINT WorkerThreadProc( LPVOID Param ) //Sample function for using in
AfxBeginThread
{
CFile file;
file.Open("C:\\Temp\\test.txt",CFile::modeCreate|CFile::modeWrite);
CString strValue;
for(int i=0;i<=100;i++)
{
strValue.Format("Value:%d",i);
file.Write(strValue,strValue.GetLength());
}
file.Close();
// more code below
...
...
...
...
return TRUE;
}
void CDummyDlg::OnExit() // Exit button handler
{
running = FALSE; // could use this to signal thread but I have to
check for it after each instruction or line of code-not good
WaitForSingleObject(hThread, INFINITE) ; // Don't wanna wait for
thread to finish must exit on user request !
CDialog::OnCancel( );
}
Now, assume thread is executing, user clicks Exit on Main GUI thread.
How can I signal above thread code to stop whatever you are doing and
exit? It is not a good software engineering to check for a Exit
condition (ie, running == FALSE) after each line of code inside thread
function. With this information once understood, I have moved from
nightmarish code to more like acceptable code-still far from close to
perfect code but I have moved forward. Thank you guys for your help
along the way. I will continue to study. Couldn't have done it
without you guys help.
.
- Follow-Ups:
- Re: Batch file and MFC (Properly Terminating Application)
- From: Joseph M . Newcomer
- Re: Batch file and MFC (Properly Terminating Application)
- From: Scott McPhillips [MVP]
- Re: Batch file and MFC (Properly Terminating Application)
- References:
- Batch file and MFC (Properly Terminating Application)
- From: one-trick-pony
- Re: Batch file and MFC (Properly Terminating Application)
- From: Joseph M . Newcomer
- Re: Batch file and MFC (Properly Terminating Application)
- From: one-trick-pony
- Re: Batch file and MFC (Properly Terminating Application)
- From: Joseph M . Newcomer
- Re: Batch file and MFC (Properly Terminating Application)
- From: one-trick-pony
- Re: Batch file and MFC (Properly Terminating Application)
- From: Joseph M . Newcomer
- Re: Batch file and MFC (Properly Terminating Application)
- From: Alexander Grigoriev
- Re: Batch file and MFC (Properly Terminating Application)
- From: Joseph M . Newcomer
- Re: Batch file and MFC (Properly Terminating Application)
- From: one-trick-pony
- Re: Batch file and MFC (Properly Terminating Application)
- From: Scott McPhillips [MVP]
- Re: Batch file and MFC (Properly Terminating Application)
- From: one-trick-pony
- Re: Batch file and MFC (Properly Terminating Application)
- From: Scott McPhillips [MVP]
- Batch file and MFC (Properly Terminating Application)
- Prev by Date: Re: BringWindowToFront/SetForegroundWindow problem
- Next by Date: Re: Batch file and MFC (Properly Terminating Application)
- Previous by thread: Re: Batch file and MFC (Properly Terminating Application)
- Next by thread: Re: Batch file and MFC (Properly Terminating Application)
- Index(es):
Loading