Permalink
Browse files

Perform all key tasks on the main thread

  • Loading branch information...
1 parent 2213fee commit 90d9af06013c9b262b4af2770f8c75c3d1d4d0e1 @danielctull committed Dec 10, 2011
Showing with 17 additions and 13 deletions.
  1. +17 −13 DCTNetworkActivityIndicatorController.m
@@ -66,27 +66,31 @@ - (void)dealloc {
- (void)decrementNetworkActivity {
- NSAssert((networkActivity > 0), @"%@ increment/decrement calls mismatch", self);
+ dispatch_async(dispatch_get_main_queue(), ^{
+ NSAssert((networkActivity > 0), @"%@ increment/decrement calls mismatch", self);
+ [self willChangeValueForKey:DCTInternal_NetworkActivityIndicatorControllerNetworkActivityKey];
+ networkActivity--;
+ [self didChangeValueForKey:DCTInternal_NetworkActivityIndicatorControllerNetworkActivityKey];
- [self willChangeValueForKey:DCTInternal_NetworkActivityIndicatorControllerNetworkActivityKey];
- networkActivity--;
- [self didChangeValueForKey:DCTInternal_NetworkActivityIndicatorControllerNetworkActivityKey];
-
- [self dctInternal_calculateNetworkActivity];
+ [self dctInternal_calculateNetworkActivity];
+ });
}
- (void)incrementNetworkActivity {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [self willChangeValueForKey:DCTInternal_NetworkActivityIndicatorControllerNetworkActivityKey];
+ networkActivity++;
+ [self didChangeValueForKey:DCTInternal_NetworkActivityIndicatorControllerNetworkActivityKey];
- [self willChangeValueForKey:DCTInternal_NetworkActivityIndicatorControllerNetworkActivityKey];
- networkActivity++;
- [self didChangeValueForKey:DCTInternal_NetworkActivityIndicatorControllerNetworkActivityKey];
-
- [self dctInternal_calculateNetworkActivity];
+ [self dctInternal_calculateNetworkActivity];
+ });
}
- (void)dctInternal_calculateNetworkActivity {
- [[NSNotificationCenter defaultCenter] postNotificationName:DCTNetworkActivityIndicatorControllerNetworkActivityChangedNotification object:self];
- [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:(networkActivity > 0)];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [[NSNotificationCenter defaultCenter] postNotificationName:DCTNetworkActivityIndicatorControllerNetworkActivityChangedNotification object:self];
+ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:(networkActivity > 0)];
+ });
}
- (NSString *)description {

0 comments on commit 90d9af0

Please sign in to comment.