PDA

View Full Version : control a detached Thread...




sujithkrishnan
Nov 13, 2008, 11:38 PM
Hi all,

Is it possible to control a detached thread??
Say. i am showing a alertView (text="Loading..", Button =Cancel) on detaching a thread which perform some server communication...
I want to giv User the flexiblity to cancel the detached thread (ConnectionHandler method) on clicking the "Cancel" button of alertView.

I know NSThread is having "cancel" method, But how to "Cancel" a detached thread?


{
Getting user inputs
Show alertView (text="Loading..", Button =Cancel)
[Detach a thread with action:@selector(connectToServer:)
}

-(void)connectToServer:(id)sender
{
// Do server communication and get response..
[self performSelectorOnMainThread with action:@selector(doneConn:)
}
-(void)doneConn:(id)sender
{
dismiss current showing alertView

}



Adding to above info:

I tried creating a thread object and initWith same selctor..
Problem is that.. in connectToServer method, i am calling another method which will really create connection using sendSynchronousRequest method of NSURLConnection.
My thread is getting cancelled only after executing sendSynchronousRequest, means... i cant cancel the Connection (in mid way of executing the same...)


Thanks for any help