Public Member Functions | |
(void) | - markAsCancelled |
(BOOL) | - cancelled |
(void) | - dealloc |
Static Public Member Functions | |
(LLThreadWorker *) | + workOn:withSelector:withObject:didEndSelector: |
(NSString *) | + description |
Protected Attributes | |
id | _target |
SEL | _selector |
id | _argument |
SEL | _didEndSelector |
NSConnection * | _callingConnection |
NSPort * | _port1 |
NSPort * | _port2 |
NSConnection * | _conn2 |
NSConditionLock * | _cancelled |
BOOL | _endRunLoop |
Definition at line 97 of file LLThreadWorker.h.
- (BOOL) cancelled |
cancelled Returns whether or not someone has tried to cancel the thread. Returns whether or not someone has tried to cancel the thread.
- (void) dealloc |
dealloc Make sure we clean up after ourselves. Make sure we clean up after ourselves.
+ (NSString *) description |
description Just a little note to say, "Good job, Rob!" Just a little note to say, "Good job, Rob!" to the original author of this Public Domain software.
- (void) markAsCancelled |
markAsCancelled Mark the LLThreadWorker as cancelled. Marks the LLThreadWorker as cancelled but doesn't actually cancel the thread. It is up to you to check whether or not the LLThreadWorker is cancelled using a two-argument "longTask:..." method like so:
+ (LLThreadWorker *) workOn: | (id) | target | ||
withSelector: | (SEL) | selector | ||
withObject: | (id) | userInfo | ||
didEndSelector: | (SEL) | didEndSelector | ||
workOn:withSelector:withObject:didEndSelector:
target | The object to receive the selector message. It is retained. | |
selector | The selector to be called on the target in the worker thread. | |
userInfo | An optional argument if you wish to pass one to the selector and target. It is retained. | |
didEndSelector | An optional selector to call on the target. Use the value 0 (zero) if you don't want a selector called at the end. |
Example:
NSDictionary *thingsIllNeed = [NSDictionary dictionaryWithObjectsAndKeys: self, @"self", myProgressIndicator, @"progress", myStatusField, @"status", nil];
[LLThreadWorker workOn:self withSelector:@selector(longTask:) withObject:thingsIllNeed didEndSelector:@selector(longTaskFinished:)];
The longTask method in self will then be called and should look something like this:
return userInfo; // Will be passed to didEndSelector }Optionally you can have this "longTask" method accept a second argument which will be the controlling LLThreadWorker instance which you can use to see if the LLThreadWorker has been marked as cancelled. Your "longTask" method might then look like this:
[LLThreadWorker workOn:self withSelector:@selector(longTask: anyNameHere:) withObject:userInfo didEndSelector:@selector(longTaskFinished:)];
When your longTask method is finished, whatever is returned from it will be passed to the didEndSelector (if it's not nil) as that selector's only argument. The didEndSelector will be called on the original thread, so if you launched the thread as a result of a user clicking on something, the longTaskFinished will be called on the main thread, which is what you need if you want to then modify any GUI components. The longTaskFinished method might look something like this, then:
import <Cocoa/Cocoa.h> import "LLThreadWorker.h"Enjoy.
Referenced by Communication::startCommunicationThread.