title: calling web services with asynchImageView
body: <p>I am having a problem in calling web services when the image are being loaded in the tableView with AsynchImageView files .</p>
  
  <p>Below are the steps of my problem:</p>
  
  <ol>
  <li>I call the web service and when it returns the data i reload the UITableView and load all images with AsynchImageView . The web service returns url of images and some text data .</li>
  <li>While the images are being loaded , if I call the same web service again then it runs for 30 seconds and then it times out without returning anything but after that time it works fine whenever I call it  .</li>
  </ol>
  
  <p>Here is my code for calling services:</p>
  
  <pre><code>-(void)getUserNotificationsPage:(int)page CallBack:(getNotifications)callback{
      dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
      dispatch_async(queue, ^ {
         @try {
  
              getNotificationsArrayResponseCallback=callback;
  
  
              NSURLRequest * urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?token=%@&amp;page=%@",GET_USER_NOTIFICATIONS,[[NSUserDefaults standardUserDefaults]objectForKey:@"token"],[NSString stringWithFormat:@"%i",page]]]];
  
  
              NSError *err;
              NSData *returnData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:nil error:&amp;err];
              if(err){
                  returnData=[NSMutableData data];
              }
  
              NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
  
  
     dispatch_async(dispatch_get_main_queue(), ^ {
  
   id json = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:nil];
  
          NSArray *returnArray=[json objectForKey:@"notifications"];
  
                  getNotificationsArrayResponseCallback(returnArray,YES);
  
              });
  
          }
          @catch (NSException *exception) {
  
  
              dispatch_async(dispatch_get_main_queue(), ^ {
  
                  UIAlertView *alert=[[UIAlertView alloc]initWithTitle:LANGUAGE(@"Unknown error occurred") message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                  [alert show];
  
  
                  getNotificationsArrayResponseCallback(nil,NO);
  
              });
          }        
       });
  }
  </code></pre>
  
  <ol start="3">
  <li><p>If I remove the code where the images are being loaded with asynchImageview then I call call the web service at any time and the response is fast at any time .</p>
  
  <pre><code>AsynchImageView *userProfileImageView =[[AsynchImageView alloc] initWithFrameURLStringAndTag:CGRectMake(5, 215, 70, 70) :[NSString stringWithFormat:@"%@%@",SERVER_URL,"some url" ];
  
  [userProfileImageView setBackgroundColor:[UIColor clearColor]];
  
  [userProfileImageView loadImageFromNetwork];
  
  [cell addSubview:userProfileImageView];
  </code></pre></li>
  </ol>
  
  <p>As you can see if I comment the line </p>
  
  <pre><code>[userProfileImageView loadImageFromNetwork];
  </code></pre>
  
  <p>then I can call the web service any number of times and the response is quick but when the asynchimage view is loading the images and then i call the service then it will time out for that time only . For further calling service works fine .</p>
  
  <p>I think this is the issue with threading or calling serveral url requests at the same time .</p>