Reputation: 454
I have the following code:
-(void) alternateQuestion
{
NSDictionary *dictQuestion=nil;
PMIiSMSQuestionModel *objQuestion=nil;
int iQuestionCount=[arrQuestion count];
for (m_iIndex=0; m_iIndex<iQuestionCount; m_iIndex++){
dictQuestion=[arrQuestion objectAtIndex:m_iIndex];
objQuestion=[[PMIiSMSQuestionModel alloc]init];
[objQuestion setM_strCode: [dictQuestion valueForKey:QUESTION_CODE]];
[objQuestion setM_strText: [dictQuestion valueForKey:QUESTION_TEXT]];
[objQuestion setM_iAnswerType:[((NSString*)[dictQuestion valueForKey:ANSWER_TYPE]) intValue]];
[objQuestion setM_iNumRangeStart: [((NSString*)[dictQuestion valueForKey:NUMBER_RANGE_START]) intValue]];
[objQuestion setM_iNumRangeEnd: [((NSString*)[dictQuestion valueForKey:NUMBER_RANGE_END]) intValue]];
[objQuestion setM_strDtRangeStart: [dictQuestion valueForKey:DATE_RANGE_START]];
[objQuestion setM_strDtRangeEnd: [dictQuestion valueForKey:DATE_RANGE_END]];
[objQuestion setM_strEmptyValue: [dictQuestion valueForKey:EMPTY_VALUE]];
[objQuestion setM_bSkipEmptyValue: [((NSString*)[dictQuestion valueForKey:SKIP_EMPTY_VALUE]) boolValue]];
[objQuestion setM_bIsMandatory:[((NSString*)[dictQuestion valueForKey:IS_MANDATORY]) boolValue]];
[objQuestion setM_iIsReadOnly: [((NSString*)[dictQuestion valueForKey:IS_READONLY]) intValue]];
[objQuestion setM_iHideIfReadOnly:[((NSString*)[dictQuestion valueForKey:HIDE_IF_READONLY]) intValue]];
[objQuestion setM_strDefaultQuestion: [dictQuestion valueForKey:DEFAULT_QUESTION]];
m_strSubCode = [dictQuestion valueForKey:@"SUBJECT_CODE"];
NSString *strTemp=[[NSString alloc]initWithFormat: CALLCARD_GET_QUESTION_QUERY,[self.m_objActiveCallcard m_iFunctionType],
[self.m_objActiveCallcard m_strCode]];
self.m_strQuery=strTemp;
strTemp=nil;
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self verifyQuestions];
//----------
});
}
As we can see the method alternateQuestion has started a background thread.We are also performing many tasks in alternateQuestion method which currently runs on the main thread. Is it advisable to move alternateQuestion method in a new background thread using GCD so that the background threads will be nested.
Thanks in advance.
Upvotes: 1
Views: 333
Reputation: 858
Check this apple documentation.
In listing 3-4, nested dispatch_async
is used.
Upvotes: 1
Reputation: 33
If you are Using GCD, No problem to launching new task. because there is no effect to main thread.
Upvotes: 0