|
|||||||
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
|
#1 |
|
Alert view blocked by background thread and preventing it to show on screen
I have a method that gets launched by a UIBarbuttonitem click. In that the first step is launch a alert view. Then a background thread starts to pull data from web service. I made sure that alert view is shown on main thread by using performselectoronmainthread. But still there is a 13 second delay from when i click the barbutton click and showing of alert view. Here is the code.
Code:
- (void)refreshDataAction
{
//Put up an alert box indicating user to wait while data is loading.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Data is Loading"
message:@"Please wait while data is being refreshed."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:FALSE];
NSLog(@"Refresh Data");
self.txtCustomerSearch.text =@"";
[self cleanUPPreviousLabels];
NSLog(@"hit in willpresenet alertview at 221");
self.refreshActIndicator.hidden = NO;
[self.refreshActIndicator startAnimating];
NSLog(@"Dispatching");
//Disable the view and all the other controls
self.txtCustomerSearch.userInteractionEnabled =NO;
self.txtCustomerSearch.enabled =NO;
self.btnSearch.enabled =NO;
self.btnSearch.userInteractionEnabled = NO;
self.scrollView.userInteractionEnabled = NO;
//self.view.userInteractionEnabled =NO;
self.chkButton.enabled = NO;
[self deletePreviousValues];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
NSLog(@"Getting customer values");
[self getAllCustomerValues];
NSLog(@"Got customer values");
NSError *nwerror = nil;
if (![self.secondMOC save:&nwerror])
{
NSLog(@"209 Failed to save second MOC");
}
else
{
//NSLog(@"saved success");
}
self.txtCustomerSearch.userInteractionEnabled = YES;
self.txtCustomerSearch.enabled =YES;
self.btnSearch.enabled =YES;
self.btnSearch.userInteractionEnabled = YES;
self.scrollView.userInteractionEnabled = YES;
self.view.userInteractionEnabled =YES;
self.chkButton.enabled = YES;
[self.refreshActIndicator stopAnimating];
NSLog(@"Saved");
});
NSLog(@"Dispatched");
}
|
|
|
|
0
|
|
|
#2 | |
|
How long does this line take to execute?:
Quote:
P.S. You don't need to use performSelectorOnMainThread: if refreshDataAction is already running on the main thread.
__________________
|
||
|
|
0
|
|
|
#3 | ||
|
@dejo. That is an excellent observation. That method was the culprit. It took 13 seconds.
So i put it in another background like this Code:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
[self deletePreviousValues];
NSLog(@"Deletion done");
});
...and other code continues like this
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
NSLog(@"Getting customer values");
[self getAllCustomerValues];
NSLog(@"Got customer values");
.....
Quote:
The exception is like this Quote:
Last edited by RookieAppler; Feb 21, 2013 at 09:46 PM. Reason: Added exception explanation |
|||
|
|
0
|
|
|
#4 |
|
Why put it in another background thread? Why not put it in the existing background thread? You want deletePreviousValues to be completed before calling getAllCustomerValues, then call them sequentially.
__________________
|
|
|
|
0
|
![]() |
|
| Tags |
| alerts, background, ios, launch, nsthread |
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 03:18 PM.








Linear Mode
