title: non-main thread does not wait for delegate methods to finish
body: <p>I am trying to use threads in my app to call web service and get data from </p>
  
  <blockquote>
    <p>connectionDidFinishLoading</p>
  </blockquote>
  
  <p>delegate method, but non-main thread does not wait for delegate methods to finish.</p>
  
  <p>here is code for thread : </p>
  
  <pre><code>dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                  //Here your non-main thread.
                  [self Login_WS];
                  //sleep(10);
  
                  dispatch_async(dispatch_get_main_queue(), ^{
                      //Here you returns to main thread.
                      //[MMProgressHUD updateProgress:1.f];
                      [MMProgressHUD dismissWithSuccess:@"done"];
                      DetailOfMenu *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"detail"];
                      //[colorVC setColor:color];
                      UINavigationController *colorNavi1 = [[UINavigationController alloc] initWithRootViewController:detail];
                      [self.qp_splitViewController setRightController:colorNavi1];
  
                      MenuTableView *colorVC = [self.storyboard instantiateViewControllerWithIdentifier:@"menu"];
                      //[colorVC setColor:color];
                      UINavigationController *colorNavi = [[UINavigationController alloc] initWithRootViewController:colorVC];
                      [self.qp_splitViewController setLeftController:colorNavi];
                  });
              });
  </code></pre>
  
  <p>and here is code for web service :</p>
  
  <pre><code>-(void)Login_WS{
  
      flag =1;
  
      NSString* ENC_UserName = [self ENC:Username.text];
      NSString* ENC_Password = [self ENC:Password.text];
  
      NSString *envelopeText = [NSString stringWithFormat: @"&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n"
                                "&lt;soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\"&gt;\n"
                                "&lt;soap12:Body&gt;\n"
                                "&lt;GetReportsNames xmlns=\"http://tempuri.org/\"&gt;\n"
                                "&lt;/GetReportsNames&gt;\n"
                                "&lt;/soap12:Body&gt;\n"
                                "&lt;/soap12:Envelope&gt;\n",];
  
      //envelopeText = [NSString stringWithFormat:envelopeText, txt1.text];
      NSData *envelope = [envelopeText dataUsingEncoding:NSUTF8StringEncoding];
  
      //NSLog(@"URL in Call_WS in SplashScreen %@",Var.url);
      NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
  
  
      [request addValue:@"http://tempuri.org/GetReportsNames" forHTTPHeaderField:@"SOAPAction"];
  
  
      [request setHTTPMethod:@"POST"];
      [request setHTTPBody:envelope];
      [request setValue:@"application/soap+xml; charset=utf-8"
     forHTTPHeaderField:@"Content-Type"];
  
      [request setValue:[NSString stringWithFormat:@"%d", [envelope length]]forHTTPHeaderField:@"Content-Length"];
  
      // fire away
      NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
      if (connection)
          responseData = [NSMutableData data];
      else
          NSLog(@"NSURLConnection initWithRequest: Failed to return a connection.");
  
  }
  </code></pre>
  
  <p>note: it is working fine in non-threading mood.</p>