Friday, April 19, 2013

NSThread setThreadPriority example objc

[NSThread setThreadPriority example] Following code fragment shows how to set thread priority with NSThread setThreadPriority method. The priority, specified with a floating point number from 0.0 to 1.0, where 1.0 is highest priority.

[NSThread setThreadPriority example]

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
[NSThread detachNewThreadSelector:@selector(threadTask) toTarget:self
withObject:nil];
[NSThread setThreadPriority:0.6];
NSLog([NSString stringWithFormat:@"%f",[NSThread threadPriority]]);

}
- (void)threadTask
{
    int i;
    NSAutoreleasePool *pool = [NSAutoreleasePool new];

  for (i=1;i<100;i++) {
    NSLog([NSString stringWithFormat:@"%d",i]);
    }

    [pool release];
    [NSThread exit];
}
@end