_client.DownloadDataAsync(new Uri(url));
_client.DownloadDataCompleted += (sender, e) =>
{
    try
    {
        if (e.Result != null && e.Result.Length > 0 && e.Error == null && e.Cancelled == false)
            using (FileStream fileStream = new FileStream(path + file_name, FileMode.Create))
                fileStream.Write(e.Result, 0, e.Result.Length);
    }
    catch (Exception ex)
    {
        OpenOperator.Error(string.Format("列表页生成任务异常,url:{0}", url), ex);
    }
};

大规模download会涉及到站点并发问题,请参见:

How to avoid the 0-byte file on Webclient download error
    





            
.Net魔法堂:开启IIS的WebGarden、WebFarm和StateServer之旅

相关文章:

  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2022-01-26
猜你喜欢
  • 2021-10-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-16
  • 2021-06-16
相关资源
相似解决方案