0

I have refresh button in my app and method 'doRefresh' who run in background thread. Now if user press double click - method doRefresh run 2 times and more. I want if user press double click and more clicks, all previos threads stop work and complete. And new method begin run in new thread. How I to do this?

More details: I work with CoreData, and parse long XML file for fill relationship objects. When user press on refresh button 10 times for example, hi catch next error:

 reason: '*** Collection <__NSCFSet: 0x5b7dd50> was mutated while being enumerated.<CFBasicHash 0x5b7dd50 [0x1503400]>{type = mutable set, count = 8   
Ilya Ilin
  • 2,283
  • 21
  • 27

1 Answers1

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.
Tech Agent
  • 657
  • 5
  • 12
  • Can I do this with background thread (performSelectorToBackground)? – Ilya Ilin Apr 28 '12 at 06:58
  • Haven't tried it byself, but it should work to have cancel variable in the object passed to the method and keeping reference of the last object passed. – Tech Agent Apr 28 '12 at 07:10