0

I have made a call to a class method from the appDelegate like so:

    RankingAndSMProcess *process = [RankingAndSMProcess alloc];

    [process performSelectorInBackground:@selector(DoRankingAndSocialMediaProcessing) withObject:nil];

    [process release];

This method calls other methods:

     @try {
         [self GoForRankingProcess];
         [self updateItemsForPeerindex];
         [self updateItemsForKloat];
         [self updateItemsForKred];
     }
     @catch (NSException *exception) {
         NSLog(@"An Error has been occured:%@", exception);
     }
     @finally { 
         [items release];
         [profile release];
     }

Do all the methods called from within the DoRankingAndSocialMediaProcessing method in RankingAndSMProcess have to be called in the same way as the DoRankingAndSocialMediaProcessing on the background thread? Or is there another potential problem here?

Currently I don't think any of the processing methods are being fired since no new data is being gathered.

Before adding changing the call to perform in the background all the methods and entire process worked as expected.

Jace
  • 145
  • 2
  • 11

2 Answers2

0

What all are those other methods doing? If it is a network request for instance a run-loop may be needed in order for the background thread to actually be able to perform the task.

Stunner
  • 12,025
  • 12
  • 86
  • 145
  • Yes, they all require a network connection which is established and checked before the @try block. Could you briefly explain how I would implement a suitable run-loop to get this working? – Jace Jul 26 '12 at 09:12
0

Create a NSOperation and add this operation to NSOperationQueue. This will create a new thread parallel to main thread and it will execute your method as well.

Here are some useful links:

NSOperation on the iPhone

http://www.icodeblog.com/tag/nsoperation/

http://www.cimgf.com/2008/02/16/cocoa-tutorial-nsoperation-and-nsoperationqueue/

Hope this will help you.

Enjoy Coding :)

Community
  • 1
  • 1
Mrunal
  • 13,982
  • 6
  • 52
  • 96