Skip navigation.
 
mlRe: Threading - How its done?
FROM : Michael Vannorsdel
DATE : Tue May 06 16:52:23 2008

There's several ways, whatever you can think of to implement canceling 
or ignoring a previous request.  For instance maybe just use an 
incrementing counter.  Before you detach the thread tell the PDF view 
what number it should expect, then pass that number to the thread, 
which will then be passed back to the PDF view from the thread.  The 
PDF view can then check if the number of the response is equal to the 
number it's currently waiting for.

Or you can identify each item in the table view with ascending numbers 
or names (a string name, file path, row number) and use that as the 
unique ID for the corresponding PDF.  The advantage to this is if the 
PDF view gets an old response back, it can cache it in a dictionary 
for when the table item it belonged to is selected again.  Before 
loading the data it can first check if the data had already been 
loaded and just grab it from the dictionary, using the unique ID as 
the key.  Caching responses depends how often you might load the same 
PDF multiple times and how large the data is.

performSelectorOnMainThread:withObject:waitUntilDone: only allows one 
argument, but you can put multiple args in an array and pass that in. 
There's better ways to pass multiple arguments such as Distributed 
Objects, but that's a whole other concept you'll have to learn.  DO is 
a mechanism where threads can communicate and pass objects back and 
forth between each other, even threads in different processes.

Also, it might make more sense to put up the progress indicator from 
the main thread before detaching to load and then dismiss the 
indicator when the PDF view gets the PDF it wants.  Since it's 
possible for multiple load threads to be running at the same time, you 
don't want them both fighting over control of the progress indicator.

As you become more familiar with threading and making it work you'll 
find more elegant ways to implement all of this.  My suggestions are 
less elegant but easier to start with.  Just remember there's no 
guarantee with the order threads will complete; it's possible a later 
request can finish before a previous one.

These are just a few ideas, but there's many ways you could handle this.


On May 6, 2008, at 7:25 AM, Karl von Moller wrote:

> I think you are right. It is the PDF loading that appears to be 
> causing the crashing. I think your guess on the previous call to the 
> Thread completing when a new PDF should load is absolutely the 
> problem. Trouble is I really don't know how to implement the Unique 
> ID system you speak of. I might have to do some serious reading 
> before advancing much from here. Any suggested reading or example 
> code I could look at?

Related mailsAuthorDate
mlRE: Threading - How its done? Karl von Moller May 6, 04:17
mlRe: Threading - How its done? John Calhoun May 6, 04:35
mlRe: Threading - How its done? Michael Vannorsdel May 6, 06:28
mlRe: Threading - How its done? Karl von Moller May 6, 06:46
mlRe: Threading - How its done? Michael Vannorsdel May 6, 07:12
mlRe: Threading - How its done? Karl von Moller May 6, 08:07
mlRe: Threading - How its done? Michael Vannorsdel May 6, 12:19
mlRe: Threading - How its done? Karl von Moller May 6, 13:04
mlRe: Threading - How its done? Michael Vannorsdel May 6, 13:10
mlRe: Threading - How its done? Karl von Moller May 6, 13:19
mlRe: Threading - How its done? Michael Vannorsdel May 6, 14:00
mlRe: Threading - How its done? Karl von Moller May 6, 15:25
mlRe: Threading - How its done? Michael Vannorsdel May 6, 16:52
mlRe: Threading - How its done? Michael Ash May 6, 18:34
mlRe: Threading - How its done? Chris Hanson May 8, 07:26
mlRe: Threading - How its done? Michael Vannorsdel May 8, 08:20
mlRe: Threading - How its done? Chris Hanson May 8, 08:45
mlRe: Threading - How its done? Michael Vannorsdel May 8, 09:16
mlRe: Threading - How its done? Scott Ribe May 8, 17:33
mlRe: Threading - How its done? Michael Vannorsdel May 9, 04:49
mlRe: Threading - How its done? Timothy Reaves May 9, 17:49