title: NSURLConnection sendAsynchronousRequest: Blocking Main Thread
body: <p>I'm using <code>NSURLConnection</code> to make multiple asynchronous requests. I'd like to show a progress indicator to show how many requests have been completed out of the total number to be performed. However, when I attempt to set up and display this progress indicator either before making the request, or in another method called before performing the request, it will not show. The progress indicator displays fine when the request is commented out. But when it's not, it's as if Xcode looks ahead and sees an asynchronous request coming and blocks the main thread, thereby making UI changes impossible.</p>
  
  <p>Here's the relevant code being called, including both the request and code to show the progress indicator:</p>
  
  <pre><code>- (void)getRegionalInformationFromChecked:(NSSet *)set atIndex:(NSInteger)index {
      __block BOOL responseRecieved = NO;
      NSString *stringForURL = [NSString stringWithFormat:@"http://www.thebluealliance.com/api/v1/event/details?event=%@",[[set allObjects] objectAtIndex:index]];
      NSURL *url = [NSURL URLWithString:stringForURL];
      NSOperationQueue *queue = [[NSOperationQueue alloc] init];
      NSLog(@"URL IS GO: %@", stringForURL);
      [NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:url] queue:queue completionHandler:^(NSURLResponse *_response, NSData *_data, NSError *_error) {
      NSLog(@"CHECKED DATA RETURNED AT INDEX %i", index);
      NSError *error;
      NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:_data options:NSJSONReadingMutableContainers error:&amp;error];
      if (!_regionalDetails) {
          _regionalDetails = [[NSMutableArray alloc] init];
      }
      [_regionalDetails addObject:dict];
      responseRecieved = YES;
  }];
      regionalSchedulesToGet = [set count];
      while (responseRecieved == NO) {}
      [[MBProgressHUD HUDForView:[[UIApplication sharedApplication] keyWindow]] setLabelText:[NSString stringWithFormat: @"Getting regional %i of %i", index+2, [set count]]];
      if (index+1 &lt; [set count]) {
          [self getRegionalInformationFromChecked:set atIndex:index+1];
      } else {
          [[MBProgressHUD HUDForView:[[UIApplication sharedApplication] keyWindow]] setLabelText:@"Writing to file"];
      }
  }
  </code></pre>
  
  <p>When the asynchronous request's block is commented out, the <code>MBProgressHUD</code> displays its value fine. But when the block is inserted, the SDK refuses to update the progress indicator, even after leaving the block (after which any threading issues should have been resolved). It does not update until there are no more requests to display, at which point it reads "Writing to file".</p>
  
  <p>Why does an asynchronous request seem to block the main thread, and why can I not make changes on the main thread immediately before or after the request is called?</p>