ios - OperationQueue is not removing the operations from queue if I call cancelAllOpeartions -


i have opeationqueue on calling cancelallopeations if ask opearationqueue.operationcount not returing me zero.

i overriding cancel method working opertioncount not zero.is expected?

see apple's api document nsoperation cancel method (emphasis mine):

this method not force operation code stop. instead, updates object’s internal flags reflect change in state. if operation has finished executing, method has no effect. canceling operation in operation queue, not yet executing, makes possible remove operation queue sooner usual.

the cancel method either mark operation 'ready' if in queue, or mark finished if not in queue. since operations in queue, means cancelled operations start 'sooner'. if sub-classed correctly, cancelled operations should mark finished , generate final kvo notifications. operations dequeued.

see responding cancel command more information cancelling custom operations.

if need know when operation queue has 0 operations left in operations array property, might consider registering queue's owner observer operationcount key path using kvo. when notified value of property has changed, can check see if value 0 , perform logic required. note nsoperations send kvo notifications on thread operating on, going background thread if run nsoperationqueue - means if need perform ui/blocking logic, need ensure run on main thread.

if decide add observer using kvo, make sure balance removing observer later. in fact, if decide leverage kvo, highly suggest digest of kvo programming guide , read through kvo api docs, short of due-diligence when working framework can result in undefined behaviors, memory leaks, or bad_access crashes.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -