ios - How to stop/cancel/suspend/resume tasks on GCD queue -



ios - How to stop/cancel/suspend/resume tasks on GCD queue -

how stop/cancel/suspend/resume tasks on gcd queue

how 1 stop background queue operations? want stop screens in our app. , screens should auto resume. so, how 1 pass queue in ios?

i mean when user have browsing app time run background thread in dispatch_queue_t. never stops , resume in code. how 1 suspend , resume queue

to suspend dispatch queue, it's dispatch_suspend(queue). doesn't impact tasks running, simply prevents new tasks starting on queue. also, suspend queues created (not global queues, not main queue).

to resume dispatch queue, it's dispatch_resume(queue). there's no concept of "auto resume", you'd have manually resume when appropriate.

to pass dispatch queue around, pass dispatch_queue_t object created when called dispatch_queue_create().

in terms of canceling tasks queued on dispatch queues, new feature of ios 8 , you'd phone call dispatch_block_cancel() dispatch_block_t object. little more complicated, i'd refer wwdc 2014 video power, performance , diagnostics: what's new in gcd , xpc, introduces concept of dispatch block objects, queuing them, canceling them, etc. frankly, if want cancel tasks, might suggest consider using operation queues (nsoperationqueue), cancelable operations have been around while , you're find lots of examples online (as not restrict ios 8).

if using operation queues, suspend , resume changing suspended property of queue. , pass around, pass nsoperationqueue object instantiated.

having said of that, i'd suggest expand question elaborate sort of tasks running in background , articulate why want suspend them. there might improve approaches suspending background queue.

ios queue grand-central-dispatch

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -