I'm writing a program that connects to a server and sends some data. This happens in a thread, which is started by a Form, which in turn has a Cancel button. I would like the connection (attempt) to be cancelled when the user presses Cancel.
So I've tried several things:Setting the worker thread to null, closing the connection, setting the connection to null, closing the input stream or output stream (all are members of the Form, the thread is an inner class of the Form). This works ok in the MMAPI emulator (which I have to use because I'm also using MMAPI functions), but at the second connection (after having cancelled one before) the phone just hangs so badly, I can't even close the Midelt anymore and have to turn it off. I'm testing with a Nokia 3650.
Which is the recommended way to abort a connection?
If my understanding is correct, it is not possible to abort a connection (I'll be gladly proved wrong!!)
Setting a reference to a Thread to null has no effect, as the VM keeps a reference to live threads. Setting a reference to the connection to null doesn't work either, because the object has a reference to itself while it's executing code ("this").
Disconnection occurs when the connection is close and all streams openned against that connection have been closed. But only of the connection is actually connected... at the point when you are trying to cancel, it is probably in the process of connecting (so, not connected yet).
I think that the connection object holds a lock on its own class while connecting... if this is so, then attempting another connection will block until the first completes or fails.