其实这也是无意间看到的,大家看看是不是这么回事
BUG:当下载线程数超过2时,就会影响到主线程响应用户请求的速度了
看ASIRequestHttp.m--requestFinished代码
- (void)requestFinished
{
#if DEBUG_REQUEST_STATUS || DEBUG_THROTTLING
ASI_DEBUG_LOG(@"[STATUS] Request finished: %@",self);
#endif
if ([selferror] || [selfmainRequest]) {
return;
}
if ([selfisPACFileRequest]) {
[selfreportFinished];
}else {
[selfperformSelectorOnMainThread:@selector(reportFinished)withObject:nilwaitUntilDone:[NSThreadisMainThread]];
}
}
你会发现在不使用自动代理脚本时,就会在主线程执行reportFinished。
解决办法:
一:继承ASIRequestHttp重写requestFinished方法;
二:懒人办法,直接修改原来ASIRequestHttp方法;看如下代码
- (void)requestFinished
{
#if DEBUG_REQUEST_STATUS || DEBUG_THROTTLING
NSLog(@"[STATUS] Request finished: %@",self);
#endif
if ([selferror] || [selfmainRequest]) {
return;
}
[selfreportFinished];
}
修改完发现至少5个下载线程时也不会影响主线程了,是不是很神奇。
上个原帖地址:http://www.keakon.net/2011/08/05/%E8%AE%A9ASIHTTPRequest%E4%B8%8D%E5%8D%A0%E7%94%A8%E4%B8%BB%E7%BA%BF%E7%A8%8B