control a detached Thread...

Discussion in 'iOS Programming' started by sujithkrishnan, Nov 13, 2008.

  1. macrumors 6502

    Joined:
    May 9, 2008
    Location:
    Bangalore
    #1
    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?

    Code:
    {
    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
     

Share This Page