sharedQueue operationCount总是上升

时间:2019-05-13 10:41:59

标签: objective-c cocoa

我使用下面的代码添加线程

static NSOperationQueue *sharedQueue = nil;
//..
sharedQueue = [[NSOperationQueue alloc] init];
//..

NSArray *a=[[NSArray alloc]initWithObjects:[@(tag) stringValue],server,filePath,userName,password,serverPath,[@(fileSize) stringValue], nil];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
        selector:@selector(newFtpOperation:) object:a ];
[sharedQueue addOperation:operation]; //add thread
//
//..

-(void)newFtpOperation:(NSArray*)aArray{

    NMSSHSession *session  = [NMSSHSession connectToHost:server withUsername:userName];
    //do something

    [session disconnect];

    //the end of newFtpOption
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ftpDone" object:[@(tag) stringValue]];

}


- (void)ftpDone:(NSNotification *)obj;{


     //[sharedQueue operationCount] always goes up rather than goes down at the end of newFtpOperation
}

但是在最后一个线程中,[sharedQueue operationCount]总是上升而不是下降。

我尝试使用

NSArray *ops=[sharedQueue operations];
[[ops objectAtIndex:[[obj object] integerValue]] cancel];

取消了NSOperation,但看起来[sharedQueue操作]元素数量没有变化

欢迎评论

0 个答案:

没有答案