日期:2014-05-20  浏览次数:20892 次

数据太大下载不下来(程序未响应),谁能帮我加一个异步操作
private   void   test()
{
    WebRequest   request   =   WebRequest.Create(url);
    WebResponse   response   =   request.GetResponse();
    request.Timeout   =   6000;
    request.Method   =   "GET ";
    request.ContentType   =   "text/xml ";
    ////加异步操作
    //发送请求并获取相应
    response   =   request.GetResponse()   as   HttpWebResponse;

    Stream   stream   =   response.GetResponseStream();
    StreamReader   sr   =   new   StreamReader(stream,   Encoding.GetEncoding( "gb2312 "));
    StreamWriter   sw   =   new   StreamWriter( "c:\\save.xml ",   false,   Encoding.GetEncoding( "gb2312 "));

    string   source;
    while   ((source   =   sr.ReadLine())   !=   null)
    {
        sw.WriteLine(source);
    }

    sw.Close();
    sr.Close();
    stream.Close();
    MessageBox.Show( "ok ");

}

------解决方案--------------------
up