zoukankan      html  css  js  c++  java
  • C#用WebClient下载File时操作超时的问题

    今天很SB,被这个问题卡住了。那段代码也是网上找的。结果发现只能下载一个文件,第二次下载的时候就会出现“操作超时”的问题。

    这个是原代码:

    System.Net.WebClient wc = new System.Net.WebClient();

    wc.OpenRead("http://patrickkroft.com/mp3/Pearl.mp3");

    Int64 bytes_total= Convert.ToInt64(wc.ResponseHeaders["Content-Length"])

    MessageBox.Show(bytes_total.ToString() + " Bytes");



    以上的代码实在是很不负责,坑爹的写的。改进成下面:

    System.Net.WebClient wc = new System.Net.WebClient();

    Stream stream = wc.OpenRead(folderEntity.URI);
    Int64 bytes_total = Convert.ToInt64(wc.ResponseHeaders["Content-Length"]);
    stream.Close(); //以及释放内存
    wc.Dispose();//及时释放,避免第二次下载时, 奇怪的"操作超时"的问题

  • 相关阅读:
    文件
    drf序列化组件
    drf入门规范
    单例模式
    初识drf
    restful规范
    虚拟环境使用
    vue基础(三)
    vue基础(二)
    作业
  • 原文地址:https://www.cnblogs.com/webfpc/p/2704365.html
Copyright © 2011-2022 走看看