iHarder.net

ThreadWorker

Taking (some) Pain out of Multithreading

Now easier than ever to use! Download v0.7 (17k)

ThreadWorker is a class whose sole class-level method makes it easy to offload a task to another thread and notify your application when you've completed the task. Creating Multithreaded applications with Objective-C in Mac OS X's Cocoa framework is easier than raw C code, but there are still some difficulties that ThreadWorker will help you overcome.

I recommend letting SourceForge notify you when I release new versions.

Be sure to copy the ThreadWorker.h and ThreadWorker.m files to your project directory.

Here is an example of how you would call ThreadWorker from your class. There is more information on the API page.

    [ThreadWorker workOn:self 
                  withSelector:@selector(longTask:) 
                  withObject:userInfo
                  didEndSelector:@selector(longTaskFinished:)];

The longTask method in self will then be called and should look like this:

     - (id)longTask:(id)someData
     {
         // Do something that takes a while and uses 'someData' if you want
         // ...
 
         return userInfo; // Will be passed to didEndSelector
     }  

Or view ThreadWorker.h or ThreadWorker.m directly.

Enjoy!

A Note About Public Domain

I have released this software into the Public Domain. That means you can do whatever you want with it. Really. You don't have to match it up with any other open source license &em; just use it. You can rename the files, do whatever you want. If your lawyers say you have to have a license, contact me, and I'll make a special release to you under whatever reasonable license you desire: MIT, BSD, GPL, whatever.