nsoperationqueue

Cancelling NSOperation from NSOperationQueue cause crash

試著忘記壹切 提交于 2019-12-06 09:35:30
I'm trying to build a download manager class that packets all the async download (every op has its own thread) operation in an NSOperation subclass to add them later in an NSOperationQueue. The download manager class (a singleton) also exposes few methods to work on the queue and cancel operations that matches some requirements. Those are steps to start creating kind of a Class Cluster(Abstract Factory) that returns different kinds of NSOperation for different types of common operation (upload, download,parse, etc). The class seems to work pretty well with download operations, but if in the

How to cancel NSOperationQueue

橙三吉。 提交于 2019-12-06 07:08:08
问题 Wondering if I'm implementing the below method correctly because isCancelled is not canceling the thread. I have an image that I'm scaling, and when it's done scaling, this method is called to update the image. So when the user lifts their finger off the button, this is called. If they try to push the button again before this is finished, I call cancelAllOperations on the queue but it's not working. Not even sure if cancelAllOperations triggers a flag, or if I need to keep calling it to get a

Any way to make dispatch_queue_t work in single thread?

时间秒杀一切 提交于 2019-12-06 06:57:14
问题 Here is my code: @interface MyObject () @property(nonatomic) dispatch_queue_t queue; @end @implementation MyObject { NSThread *_check; } - (id)init { self = [super init]; if (self) { _queue = dispatch_queue_create("com.Thread.queue", NULL); dispatch_async(_queue, ^{ _check = [NSThread currentThread]; //for ex. thread number = 3 //some code here... }); } return self; } - (void)someMethod:(MyObjClass *)obj { dispatch_async(_queue, ^{ //need th if (_check != [NSThread currentThread]) { // it is

Fixing my network activity indicator

岁酱吖の 提交于 2019-12-05 21:36:00
I have a problem with my network activity indicator in that sometimes it will continue to be displayed when it should not be. I wrote my own manager for it and swapped it out for one that uses an NSAssert statement like this... - (void)setNetworkActivityIndicatorVisible:(BOOL)setVisible { static NSInteger NumberOfCallsToSetVisible = 0; if (setVisible) NumberOfCallsToSetVisible++; else NumberOfCallsToSetVisible--; // The assertion helps to find programmer errors in activity indicator management. // Since a negative NumberOfCallsToSetVisible is not a fatal error, // it should probably be removed

iOS开发 多线程(三)转自MJ的NSOperationQueue使用

偶尔善良 提交于 2019-12-05 12:58:10
一、简介 一个NSOperation对象可以通过调用start方法来执行任务,默认是同步执行的。也可以将NSOperation添加到一个NSOperationQueue(操作队列)中去执行,而且是异步执行的。 创建一个操作队列: [java] view plain copy NSOperationQueue *queue = [[NSOperationQueue alloc] init]; 二、添加 NSOperation 到 NSOperationQueue 中 1.添加一个operation [java] view plain copy [queue addOperation:operation]; 2.添加一组operation [java] view plain copy [queue addOperations:operations waitUntilFinished:NO]; 3.添加一个block形式的operation [java] view plain copy [queue addOperationWithBlock:^() { NSLog(@ "执行一个新的操作,线程:%@" , [NSThread currentThread]); }]; NSOperation添加到queue之后,通常短时间内就会得到运行。但是如果存在依赖,或者整个queue被暂停等原因

Can't cancel executing operations in OperationQueue swift

被刻印的时光 ゝ 提交于 2019-12-05 12:06:15
Im doing some lengthy calculations to create chart data on a background thread i was originally use GCD, but every time a user filters the chart data by hitting a button, the chart data needs to be recalculated, if the user clicks the chart data filtering buttons very quickly (power user) then the chart loops through each drawing as each GCD dispatch async finishes I realize that I can't cancel threads with GCD so I've moved to trying to implement an OperationQueue I call cancelAllOperations() before adding a new operation to the queue The operations on the queue act funky, sometimes it seems

Barrier operations in NSOperationQueue

自古美人都是妖i 提交于 2019-12-05 09:08:07
How can we implement dispatch_barrier_async 's equivalent behavior using NSOperationQueue or any user-defined data-structure based on NSOperationQueue ? The requirement is, whenever a barrier operation is submitted it should wait until all non-barrier operations submitted earlier finish their execution and blocks other operations submitted after that. Non-barrier operations should be able to perform concurrently. Barrier operations should execute serially. NB: Not using GCD ,as it doesn't provide(or atleast difficult) much access over the operations, like cancelling single operation, etc. Clay

NSOperationQueue - Getting Completion Call Too Early

萝らか妹 提交于 2019-12-05 08:00:55
问题 I am using a NSOperationQueue to queue and call a number of Geocoding location lookups. I want to call a completion method when all asynchronicly running lookups have been finished. -(void)geocodeAllItems { NSOperationQueue *geoCodeQueue = [[NSOperationQueue alloc]init]; [geoCodeQueue setName:@"Geocode Queue"]; for (EventItem *item in [[EventItemStore sharedStore] allItems]) { if (item.eventLocationCLLocation){ NSLog(@"-Location Saved already. Skipping-"); continue; } [geoCodeQueue

NSOperationQueue, concurrent operation and thread

白昼怎懂夜的黑 提交于 2019-12-05 05:21:11
问题 I'm developing a sort of fast image scan application. In the -captureOutput:didOutputSampleBuffer:fromConnection: method I pick up the CVPixelBuffer and add them into an NSOperation subclass. The NSOperation takes the buffer and transform it into an image saved on the filesystem. The -isConcurrent method of NSOperation returns YES. After the operation is created, is added to an NSOperationQueue . Everything runs fine except for one issue that is affecting the scan frame rate. Using time

Cancel NSOperation in for loop?

♀尐吖头ヾ 提交于 2019-12-05 02:06:55
问题 I am trying to implement search on a background thread using NSOperation on iOS . I didn't want to subclass NSOperation so this is what I'm doing: [searchQueue cancelAllOperations]; NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self elector:@selector(filterContentForSearchText:) object:self.searchDisplayController.searchBar.text]; [searchQueue addOperation:op]; [op release]; The search method includes a for loop that checks whether what is being searched is in an