久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 iOS 中殺死 dispatch_async 隊列中的項目

kill items in a dispatch_async queue in iOS(在 iOS 中殺死 dispatch_async 隊列中的項目)
本文介紹了在 iOS 中殺死 dispatch_async 隊列中的項目的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在使用 dispatch_async 在后臺運行一堆項目,有時我想殺死隊列中的內容 - 這可能嗎?例如,此代碼在視圖上運行,然后用戶返回屏幕.無論返回導航如何,所有這些觸發的操作都會繼續運行.理想情況下,我想阻止這些項目運行:

I am running a bunch of items in the background using dispatch_async and sometimes I want to kill what I have in the queue - is this possible? For instance this code is run on a view, and then the user goes back a screen. All of these fired actions keep running regardless of the back navigation. Ideally I would like to kill these items from running:

dispatch_async(dispatch_get_global_queue(2, 0), ^{
        for (int i=0; i<[self.manufacturers count]; i++) {
            NSString *manufacturerID = [[[self.manufacturers objectAtIndex:i] ManufacturerID] stringValue];
            [self doSync:manufacturerID withIndex:i setTimer:YES];
        }
    });

如果我創建一個隊列并命名它,然后在調用視圖的 dealloc 上釋放它,它們仍然會繼續運行.

If I create a queue and name it and then release it on the dealloc of the view this is called in they still continue to run.

推薦答案

調度隊列中沒有明確規定終止.為了做到這一點,測試一個逃生位置以確定終止是有點常見的.基本上,這將是一個信號量.

There's no explicit provision in dispatch queues for termination. In order to do this, it is somewhat common to test an escape location to determine termination. Basically, it'd be a semaphore.

NSOperationQueue(更高級別的抽象,但仍然在底層使用 GCD 構建)確實支持取消操作.因此,例如,您可以創建一系列 NSOperations 并將它們添加到 NSOperationQueue,然后在不需要完成時將 -cancelAllOperations 消息發送到隊列.

NSOperationQueue (a higher level abstraction, but still build using GCD underneath) does have support for canceling operations. So, for example, you can create a series of NSOperations and add them to an NSOperationQueue and then message -cancelAllOperations to the queue when you don't need it to complete.

您選擇的很多架構將取決于其中有多少正在運行以及它們是否具有不同的觸發器.在這些實現中,NSOperation 可能是最干凈"的解決方案,因為您有一個任意隊列,您可以在該隊列中觀察要完成的操作,還可以取消未完成的操作.進一步降低黑客規模將是一個不穩定的位置,這些塊中的每一個都在一個緊密的循環內監視,以確定它們是否會過早完成.再往下是相同基本功能的全局變量.

A lot of the architecture you choose will depend on how many of these are operating and whether they have different triggers. Among the implementations, NSOperation is likely the "cleanest" solution, since you have an arbitrary queue which you can watch for operations to be finished on and you can also cancel outstanding operations. Further down the scale of hack would be a volatile location that each of these blocks watch inside of a tight loop to determine if they're going to finish prematurely. Yet further down would be a global variable for the same basic function.

最后,即使是 NSOperation 的實現也涉及到一個測試,以便在一個一致的位置退出(因為僅僅殺死一個線程可能會導致正在操作的數據或分配/重新訓練中的數據不一致).

In the end, even the implementation of NSOperation involves a test in order to exit in a consistent location (since just killing a thread might result in inconsistencies in the data being operated upon or in allocations/retrains).

這篇關于在 iOS 中殺死 dispatch_async 隊列中的項目的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

KIF: How to auto-run/stress test an iOS app to find the cause of a rare UI bug?(KIF:如何自動運行/壓力測試 iOS 應用程序以找出罕見 UI 錯誤的原因?)
Can#39;t change target membership visibility in Xcode 4.5(無法更改 Xcode 4.5 中的目標成員身份可見性)
UITableView: Handle cell selection in a mixed cell table view static and dynamic cells(UITableView:在混合單元格表視圖靜態和動態單元格中處理單元格選擇)
How to remove Address Bar in Safari in iOS?(如何在 iOS 中刪除 Safari 中的地址欄?)
iOS 5 SDK is gone after upgrade to Xcode 4.5(升級到 Xcode 4.5 后,iOS 5 SDK 消失了)
Having trouble creating UIImage from CIImage in iOS5(在 iOS5 中從 CIImage 創建 UIImage 時遇到問題)
主站蜘蛛池模板: 懂色中文一区二区三区在线视频 | 亚州成人| 亚洲一区视频 | 亚洲小说图片 | 黄色大片在线免费观看 | 成人免费黄视频 | 水蜜桃亚洲一二三四在线 | 一区二区成人 | 日韩国产一区二区 | 国产精品一区在线观看 | www.色午夜.com | 精品欧美黑人一区二区三区 | 亚洲精品日韩精品 | 日本午夜一区 | 久久久免费 | 91视频网址 | 免费看黄视频网站 | 美女拍拍拍网站 | 一区二区三区久久久 | 久久精品无码一区二区三区 | 天天综合久久 | 四色成人av永久网址 | 91 久久| 视频一区二区在线观看 | 美女天天干天天操 | 91精品久久久 | 夜夜夜夜夜夜曰天天天 | 中文字幕欧美在线观看 | 日本午夜视频 | www在线| 国产高清一区二区 | 美国十次成人欧美色导视频 | 亚洲欧美激情国产综合久久久 | 免费视频一区二区 | 国产精品一区久久久 | 最新超碰 | 国产精品福利视频 | 精品久久久久久久久久久久久久 | 日韩h| 日本成人福利视频 | 欧美成人免费 |