0

doRefresh在后台线程中运行的应用程序和方法“”中有刷新按钮。现在,如果用户按下双击 - 方法doRefresh运行 2 次或更多次。我希望如果用户按下双击和更多的点击,所有 previos 线程停止工作并完成。新方法开始在新线程中运行。我该怎么做?

更多细节:我使用 CoreData,并为填充关系对象解析长 XML 文件。例如,当用户按下刷新按钮 10 次时,hi catch 下一个错误:

 reason: '*** Collection <__NSCFSet: 0x5b7dd50> was mutated while being enumerated.<CFBasicHash 0x5b7dd50 [0x1503400]>{type = mutable set, count = 8   
4

1 回答 1

1
Here's how things may work
1. Keep a reference to last thread spawned
2. In each thread spawned keep a variable, say var_cancel
3. When a new thread is created, set the var_cancel to true for previous thread.
4. In the thread, check for var_cancel at short durations. If found true, exit the thread.
5. Make sure the thread does not produce any side effects between var_cancel set true to exit of thread.
于 2012-04-28T06:56:05.870 回答