Exiting a program

P

Paul G. Tobey [eMVP]

You need to make sure that the thread exits before you try to exit the main
application thread, yes. If a thread is created with CreateThread() and you
keep the handle returned from that call, you have to close the handle to
keep from leaking it. The end of the application is an obvious time to do
that, also. In my unmanaged code, I do something roughly like this to fire
an event which notifies the thread to exit, waits for the thread to exit,
and then closes the thread handle.

if ( hThread != NULL )
{
// Notify thread that it's time for it to terminate.
SetEvent( hEvent );

// Wait for the thread to exit.
WaitForSingleObject( hThread, 5000 ); // Will wait five seconds or
until thread exits.

CloseHandle( hThread );
hThread = NULL;
}

if ( hEvent != NULL )
{
CloseHandle( hEvent ); // Don't leak the event handle, either.
hEvent = NULL;
}

So, you want to end up doing the equivalent steps in managed code...

Paul T.
 
G

Guest

I have one,

I'm using some Forms on my App, but when I close one of them
programmatically still there in memory the MinimizeBox = False doesn't helps
because I'm closing my form on my program, and the Application.Exit doesn't
works here because I won't to Exit my App, just close one form. What I need
to do?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top