多线程,后台进程

-(void)doWork:(id)sender

{

    NSDate *startTime=[NSDate date];

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    

        NSString *fetchedData=[self fetchSomethingFromServer];

        NSString *processedData=[self processData:fetchedData];

        NSString *firstResult=[self calculateFirstResult:processedData];

        NSString *secondResult=[self calculateSecondResult:processedData];

        

        NSString *resultSummary=[NSString stringWithFormat:@"First:[%@]\nSecond:[%@]",firstResult,secondResult];

        

        UITextView *textView=(UITextView *)[self.view viewWithTag:102];

        textView.text=resultSummary;

        NSDate *endTime=[NSDate date];

        NSLog(@"Completed in  %f Seconds",[endTime timeIntervalSinceDate:startTime]);

    });

    


}


一直比较一知半解,没正经用过,好好看看。


2013-04-01 14:54:39.742 Rubic's Cube No StoryBoard[2891:15807] bool _WebTryThreadLock(bool), 0xa068ce0: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...

1   0x56966a9 WebThreadLock

2   0x4eaa7e -[UITextView setText:]

3   0xbb0a __37-[ForInterviewViewController doWork:]_block_invoke_0

4   0x1a3053f _dispatch_call_block_and_release

5   0x1a42014 _dispatch_client_callout

6   0x1a332e8 _dispatch_root_queue_drain

7   0x1a32fcb _dispatch_worker_thread3

8   0x9836bb24 _pthread_wqthread

9   0x9836d6fe start_wqthread

问题原因在于:UIKit的线程安全性。请记住,从后台线程联系任何GUI对象是绝对不可能的。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值