Re: Batch file and MFC (Properly Terminating Application)



one-trick-pony wrote:
I am having some difficulty, when instruction, delete myWorkerThread,
is executed-my application crashes and Send Error Report to Microsoft
window appears. When I comment out the line, I don't get that
error.


I have a few questions regarding slowing down application for user.
For example, I would like to give users a few seconds to choose
between action A or action B if user doesnt choose anything a default
action is made by application. I relied on Sleep function so far to
accomplish this. I would like to stop using sleep and implement the
desired behavior. Also, same goes for showing a splash screen. I want
to suspend/slow down for maybe a couple of seconds so users see a
splash screen. Usually, splash screens are used for decoy to quickly
start crunching application code. Furthermore, I like to be able to
suspend my application at times. Again, I relied on sleep so far to
implement suspend behavior.

You need to set the CWinThread's m_bAutoDelete to FALSE (before it executes!) to be sure the object will still exist when you delete it. Like this:

// Start thread with auto delete off
pThread = AfxBeginThread(ThreadProc, pParam,
THREAD_PRIORITY_NORMAL, 0,
CREATE_SUSPENDED);
pThread->m_bAutoDelete = FALSE;
pThread->ResumeThread();

All of your time delay questions are answered with SetTimer and a message handler for WM_TIMER. You set the timer interval, then you get a WM_TIMER message every interval.

> Furthermore, I like to be able to
> suspend my application at times. Again, I relied on sleep so far to
> implement suspend behavior.

Your application should return to MFC whenever you complete handling a message. MFC suspends it until a new message arrives. So maybe it already does what you want. What are you trying to accomplish?

--
Scott McPhillips [VC++ MVP]

.



Relevant Pages


Loading