iphone开发——同时新建多个线程不执行的问题

今天遇到一个奇怪的问题,使用NSOperationQueue连续添加多个子线程时出现子线程不执行的问题。解决方法如下:

在连续的打开多个子线程时,设置一定的时间间隔。    [NSThread sleepForTimeInterval:0.1];

 

    NSInvocationOperation * theOp = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(getDetailProfile:) object:(void *)0];
    [[Func appOperationQueue] addOperation:theOp];
    [theOp release];
    
    [NSThread sleepForTimeInterval:0.1]; //不能省略此处代码。联系添加多线程时,应设置一定时间间隔
    
    NSInvocationOperation * theOp1 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(getDetailProfile:) object:(void *)1];
    [[Func appOperationQueue] addOperation:theOp1];
    [theOp1 release];
    
    [NSThread sleepForTimeInterval:0.1];//不能省略此处代码。联系添加多线程时,应设置一定时间间隔

    NSInvocationOperation * theOp2 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(getDetailProfile:) object:(void *)2];
    [[Func appOperationQueue] addOperation:theOp2];
    [theOp2 release];
    
    [NSThread sleepForTimeInterval:0.1];//不能省略此处代码。联系添加多线程时,应设置一定时间间隔
    
    NSInvocationOperation * theOp3 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(getDetailProfile:) object:(void *)3];
    [[Func appOperationQueue] addOperation:theOp3];
    [theOp3 release];
    
    [NSThread sleepForTimeInterval:0.1];//不能省略此处代码。联系添加多线程时,应设置一定时间间隔
    
    NSInvocationOperation * theOp4 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(getDetailProfile:) object:(void *)4];
    [[Func appOperationQueue] addOperation:theOp4];
    [theOp4 release];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值