using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading.Tasks; using System.Net; using System.Web;
异步请求需要运行循环.当数据传递到服务器或是被客户端接收时,运行循环用于实现事件与委托对象之间的通信.异步请求在发出时,会在当前线程的运行循环上操作,这个实现细节是很重要的,因为在GCD块中或者是通过NSOperationQueue创建的线程并没有运行循环.因此,如果在后台线程上发出了异步请求,那么还需要确定线程是有运行循环还是使用了别的运行循环.如下代码片断展示了如何显示地将请求处理指定给运行循环. NSURLConnection connection=[[NSURLConnection al