Performing a Completion Block When a Task Is Done (!!!)
2014-08-29 14:03
260 查看
Executing a completion callback after a task :
void average_async(int *data, size_t len, dispatch_queue_t queue, void (^block)(int)) { // Retain the queue provided by the user to make // sure it does not disappear before the completion // block can be called. dispatch_retain(queue); // Do the work on the default concurrent queue and then // call the user-provided block with the results. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ int avg = average(data, len); dispatch_async(queue, ^{ block(avg);}); // Release the user-provided queue when done dispatch_release(queue); }); }
相关文章推荐
- How to trigger an Animation when TextBlock’s Text is changed during a DataBinding
- Variable 'bop' is uninitialized when captured by block
- Fix Backup Database is terminating abnormally When performing a Farm Backup
- How To Determine When a Page Is Done Loading in WebBrowser Control
- Fix Backup Database is terminating abnormally When performing a Farm Backup
- WP7“Navigation is not allowed when the task is not in the foreground.”解决方案
- Fix Backup Database is terminating abnormally When performing a Farm Backup
- WP7“Navigation is not allowed when the task is not in the foreground.”解决方案
- RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile canno
- 误操作:释放栈上空间 Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
- When ESC is pressed, change the color of the character.
- ERROR: current transaction is aborted, commands ignored until end of transaction block
- Superblock mount time is in the future(转载)
- Is an MTD device a block device or a char device?
- When Replicat is Running but Not Applying Records [ID 1124403.1]
- Attribute value is quoted with " which must be escaped when used within the value 问题解决
- when i run server i got "name 'http' is not defined" after import h 4000 ttp.server then i got this "no mo
- field is not Date/numeric when export excel using reporting service
- idea @Override is not allowed when implementing interface method
- Well begun is half done!