-2
threadss.h
-----------
#import <Foundation/Foundation.h>
@interface threadss : NSObject {
BOOL m_bRunThread;
int a,b,c;
}
-(void)startThread;
-(void)insert;
-(void)display;
@end
threadss.m
------------
import "threadss.h"
@implementation threadss
-(void)startThread
{
m_bRunThread = YES;
NSOperationQueue* queue = [[NSOperationQueue alloc]init];
//NSInvocationOperation* operation = [[NSInvocationOperation alloc]initWithTarget:self selector:@selector(display) object:nil];
//[queue addOperation:operation];
[[self insert] performSelectorOnMainThread:@selector(display) withObject:nil waitUntilDone:YES];
[queue release];
//[operation release];
}
-(void)insert
{
NSLog(@"Into The Insert Event!!");
a=10;
b=20;
c = a + b;
}
-(void)display
{
NSLog(@"Into the display method");
NSLog(@"The value od c is:%d",c);
}
@end
main.m
-------
#import <Foundation/Foundation.h>
#import "threadss.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
threadss* thread = [[threadss alloc]init];
[thread startThread];
[pool drain];
return 0;
}
error:
------
void value not ignored as it ought to be
我的意思是首先調用顯示方法,然後我想打電話給插入method.The dispaly方法必須等待插入的方法做處理它應在完成時發出顯示線。 – spandana 2011-06-01 12:16:55
如果按照我寫的方式執行,插入將在您創建的線程上完成,並在插入完成後在主線程上顯示。以該順序。所以我沒有看到回調的原因。 – vakio 2011-06-01 12:37:28
是這樣做很容易。而且它並不是完成一項工作。 – spandana 2011-06-01 13:38:20