Newbie question: Gracefully crashing app at Windows terminatin 
Author Message
 Newbie question: Gracefully crashing app at Windows terminatin

>I have an App-wizard generated app with my code al in a worker
>thread that has no user interaction.  It can be closed just fine from
>the main window, but I have two questions.  
>1.  How do I tel the worker thread to do termination processing when the
>main thread is closed?  
>2.  How do I handle Win95 being shut down when my proram is still
>running?  The tester said it ended abnormally under that situation.  


I'd arrange for the worker thread to periodically wait for an event,
then when the main thread is shutting down have it signal the event
and wait for the worker thraed to terminate before it continues.

Here's a snippet of code from an OnDestroy handler I have:

        /* Signal the child thread to shut down */
        SetEvent( ghExitEvent );

        /* Wait until the child thread has stopped */
        while ( ghThread != NULL )
                DWORD Code;

                if ( !GetExitCodeThread( ghThread, &Code ) ||
                        ( Code != STILL_ACTIVE ) )
                        /* relinquish hold of the thread handle */
                        CloseHandle( ghThread );
                        ghThread = NULL;
                        /* Be slightly better behaved by
                         * yeilding for a short period
                        Sleep( 500 );

Address is altered to discourage junk mail.
Remove ".---" for the real address.

Thu, 22 Jul 1999 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. How to gracefully shut down console app.

2. How to gracefully handle app closing

3. newbie: why does my app crash?

4. Newbie: Why does my app crash?

5. IGlobalInterfaceTable::RevokeInterfaceFromGlobal crashes app on Windows XP

6. DAO app crashes under Windows ME / XP

7. Windows Service Checking for crashed dll in a MDI app

8. App crashes when Windows shuts down

9. String modification crash--Newbie question

10. DOA app crashes with a Kernel Crash on exit

11. newbie Q: command line args for win32 app on windows CE

12. Newbie question - crash when reopening a modeless dialog


Powered by phpBB® Forum Software