title: How to cancel/exit/stop execution of Thread object or thread running in background in IOS
body: <p>I am detaching a thread to do some operation in the background, refer the code as below</p>
  <pre><code> currentThread = [[NSThread   alloc]initWithTarget:contactServiceselector:@selector(requestForContactBackup:)object:msisdn];
  
   [currentThread start];
  </code></pre>
  <p>This currentThread is the pointer declared in AppDelegate.
  I have a button on my view, on tap of it, the execution of background thread should stop. Refer the below code:</p>
  <pre><code>-(void)cancelTheRunningTasks {
      
     if(self.currentThread !=nil) {
  
          [currentThread cancel];
          NSLog(@&quot;IsCancelled: %d&quot;,[currentThread isCancelled]);   //here Yes returns
          [self removeNetworkIndicatorInView:backUpViewController.view];
      }  
  }
  </code></pre>
  <p>Problem with the below code is that the background thread is still remains in execution.</p>
  <p>My question would be, having the thread reference, how to cancel/stop execution/kill the background thread from main thread?</p>
  <p>please suggest me possible solution.
  Thanks.</p>