Aborting threads before quit my application using Application.Exit

C

Chris Tacke, eMVP

Have you put in a break point or debug message to see if your thread
actually exits? The 10 seconds of sleep is also highly suspect.

--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
 
G

Guest

HEY CRIS!

Your solution worked for me!!!
I need to wait a little betwen closing the port and disposing the object,
but now it works fine!!!

I don't know why I didn't had this idea before.... I think I need to relax a
little! :)

Thank you, and thanks for the help, guys (Daniel, Sergey and Paul!)
 
S

Sergey Bogdanov

Yes I knew it and completely agree with you, but I have just noticed
that it was not an issue in this case and Thanya may leave this event
unclosed because OS will close it anyway when process will die...

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
G

Guest

Well,

Chris's suggestion worked yesterday, but not today.

Today I saw in debug mode that the part

while ( WaitForSingleObject( m_hEvtQuit, 0 ) != WAIT_OBJECT_0 )
{
// do some processing
}

port.Enabled = false;
port.Dispose();
CloseHandle(hQueue);
CloseHandle(m_hEvtQuit);

This closing part is executed three times .... I'm calling it once, but the
code still here for three times, the application quit in the pocket pc but
the debug session still on, signaling the application does not quit right.

I don't know what I can do anymore :(
 
P

Paul G. Tobey [eMVP]

You really need to sit down and understand what's supposed to be happening
so that you'll recognize when things are wrong. When I look at that small
bit of code, the first thing I think of is, what processing? Do any of the
calls inside the loop block? Which ones? If there are any, then, when I'm
trying to exit the application, I have to make sure that those calls are
released, or they'll continue to block and the thread will still exist.

Based on your previous messages, it also sounds like you are P/Invoking to
some external library, right? What do you know about the threading model
used by that?

If you're going to write complex applications which are using threading, you
*have to* understand what threading is about, how to cleanly exit threads,
and you have to know what's happening in any code you're calling from the
thread.

Paul T.
 

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