0

アプリとメソッドに更新ボタンがありdoRefresh、バックグラウンドスレッドで実行されます。ここで、ユーザーがダブルクリックを押すと、メソッドdoRefreshは2回以上実行されます。ユーザーがダブルクリックを押してさらにクリックすると、以前のすべてのスレッドが機能を停止して完了します。そして、新しいメソッドが新しいスレッドで実行を開始します。どうすればいいですか?

詳細:CoreDataを使用して、塗りつぶし関係オブジェクトの長いXMLファイルを解析します。たとえば、ユーザーが更新ボタンを10回押すと、次のエラーが発生します。

 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 に答える