0
爲什麼我的NSOperation子類在主線程上運行主方法?我希望它異步運行。NSOperation - 主要方法在主線程上運行?
@interface ServiceClient : NSOperation
@end
@implementation ServiceClient
- (void)main
{
if ([[NSThread currentThread] isEqual:[NSThread mainThread]])
{
NSLog(@"Why does this get called on the main thread");
}
}
@end
啓動操作
ServiceClient *serviceClient = [[ServiceClient aloc] init];
[serviceClient start];
編輯:
文檔建議重寫isCuncurrent和返回是的,但該方法不會被調用。
- (BOOL)isConcurrent
{
return YES;
}
你是否從通過NSOperationQueue開始操作獲得相同的行爲? –
出於興趣,[NSThread isMainThread]是否也返回true?我不確定你的平等測試。 – Senior
我試圖將操作添加到NSOperationQueue並在後臺運行它(不同的線程),但是可以在單獨的線程上運行該操作而不將其添加到OperationQueue中? – aryaxt