标签: downloadfileasync

WebClient.DownloadFileAsync真的这么慢吗?

我正在使用从服务器下载一些文件的DownloadFileAsync方法WebClient,我不禁注意到在VS2010中我的代码的非正式测试中,它在启动时会阻塞大约3秒钟,在我看来,首先打败了目的.

以下是相关的代码片段:

WebClient downloader = new WebClient();
downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(updateDownloadProgress);
downloader.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(downloadCompleted);

var current_map = map_downloads[0];//string with filename, map_downloads is List<string>

var path = System.IO.Path.GetTempFileName();

downloaded_maps.Add(path);//adding the temp file to a List<string>

downloader.DownloadFileAsync(new Uri(MAP_BASE + current_map), path); //MAP_BASE is a string containing the base url
Run Code Online (Sandbox Code Playgroud)

DownloadFileAsync当应用程序下载~100 MB文件时,我正在使用UI阻止阻止.显然,如果UI在呼叫开始时阻塞了3秒,那么即使不完全,也会稍微减少效用.

我对C#/ .Net相对缺乏经验(大约3 - 4年前我做了一堆.Net 2.0的东西,IIRC,但我现在基本上重新学习它).

c# performance webclient downloadfileasync

7
推荐指数
3
解决办法
6308
查看次数

WebClient DownloadFileAsync挂起

美好的一天.我正在使用DownloadFileAsync处理文件下载器类.在正常情况下一切正常.但是当我下载文件并禁用网络连接时,下载进度只是停止无限时间,不会引发任何错误或调用任何回调.任何想法如何处理这种情况?非常感谢.

_client.Proxy = WebRequest.DefaultWebProxy;
_client.DownloadProgressChanged += (sender, argv) => { actionCallback(argv.ProgressPercentage); }
_client.DownloadFileCompleted += (sender, argv) => { 
      if (argv.Error != null) { 
          _exc = argv.Error;
      } 
      set event
}
 Task.Factory.StartNew(() => {
     _client.DownloadFileAsync(request, targetFileName);

     thread sync

     if (_exc != null) {
         logger.ErrorException(exc);
         throw;
     }
Run Code Online (Sandbox Code Playgroud)

问题出现在Vista和2k8下.在Win7上一切正常.

c# download .net-4.0 hang downloadfileasync

6
推荐指数
1
解决办法
1068
查看次数

如何在.net上为WebClient设置TimeOut?

我下载了一些文件,但我也想为webclient设置超时.我看到没有变化只是我们可以使用重写WebRequest.我已经做了但它不起作用.我的意思是重写GetWebRequest方法不起作用..这是我的代码

  public class VideoDownloader : Downloader
{
    /// <summary>
    /// Initializes a new instance of the <see cref="VideoDownloader"/> class.
    /// </summary>
    /// <param name="video">The video to download.</param>
    /// <param name="savePath">The path to save the video.</param>
    public VideoDownloader(VideoInfo video, string savePath)
        : base(video, savePath)
    { }


    /// <summary>
    /// Starts the video download.
    /// </summary>
    public override void Execute()
    {
        // We need a handle to keep the method synchronously
        var handle = new ManualResetEvent(false);

        var client = new WebClient();


        client.DownloadFileCompleted …
Run Code Online (Sandbox Code Playgroud)

c# timeout webclient webrequest downloadfileasync

6
推荐指数
1
解决办法
1万
查看次数

并行下载文件的最佳数量

我正在尝试同时下载多个文件。如何确定并行下载的最佳文件数量?

c# parallel-processing webclient downloadfileasync

3
推荐指数
1
解决办法
2333
查看次数

WebClient DownloadFileAsync() 不起作用

WebClient DownloadFileAsync() 不适用于相同的 URl 和凭据...

有什么线索吗?

 static void Main(string[] args)
        {
            try
            {
                var urlAddress = "http://mywebsite.com/msexceldoc.xlsx";


                using (var client = new WebClient())
                {
                    client.Credentials = new NetworkCredential("UserName", "Password");
                    // It works fine.  
                    client.DownloadFile(urlAddress, @"D:\1.xlsx");
                }

                /*using (var client = new WebClient())
                {
                   client.Credentials = new NetworkCredential("UserName", "Password");

                    // It y creats file with 0 bytes. Dunow why is it. 
                    client.DownloadFileAsync(new Uri(urlAddress), @"D:\1.xlsx");
                    //client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);

                }*/
            }
            catch (Exception ex)
            {

            }
        }
Run Code Online (Sandbox Code Playgroud)

.net c# webclient downloadfileasync

2
推荐指数
1
解决办法
3917
查看次数

Webclient downloadfileasync无法正常工作

我有一个WPF应用程序,我想下载一个文件.

我正在使用System.Net; 我有以下代码:

WebClient ww = new WebClient();
ww.DownloadFileAsync(
    new Uri("http://www.sinvise.net/tester/1.jpg"), 
    AppDomain.CurrentDomain.BaseDirectory + "\\1.jpg");
Run Code Online (Sandbox Code Playgroud)

问题是,它是不下载文件,它只是显示为0kb文件而不是下载,我不知道是什么问题,任何人都可以帮忙吗?

c# webclient downloadfileasync

1
推荐指数
1
解决办法
8194
查看次数

如何在C#中成功下载.exe文件?

我正在尝试test.exe使用以下代码下载文件:

public void DownloadFile()
{
    using(var client = new WebClient())
    {
         client.DownloadFileAsync(new Uri("http://www.acromix.net16.net/download/test.exe"), "test.exe");
    }
}
Run Code Online (Sandbox Code Playgroud)

使用这个简单的代码,我调试它,这是输出: 产量

我不知道,也不知道为什么它是0 KB(应该是328 KB).[ / downloads ]

我怎样才能使它工作?

编辑: 托管网站(000webhost)阻止.exe文件下载...

c# download downloadfileasync async-await webclient-download

1
推荐指数
1
解决办法
844
查看次数

Android下载apk文件并保存到内部存储

在开发允许用户检查新应用程序更新的功能时,我已经呆了好几天(我使用本地服务器作为分发点)。问题是下载进度似乎工作正常,但我在手机的任何位置都找不到下载的文件(我没有SD卡/外部存储器)。以下是我到目前为止所取得的成就。

 class DownloadFileFromURL extends AsyncTask<String, String, String> {
    ProgressDialog pd;
    String path = getFilesDir() + "/myapp.apk";
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pd = new ProgressDialog(DashboardActivity.this);
        pd.setTitle("Processing...");
        pd.setMessage("Please wait.");
        pd.setMax(100);
        pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        pd.setCancelable(true);
        //pd.setIndeterminate(true);
        pd.show();

    }

    /**
     * Downloading file in background thread
     * */
    @Override
    protected String doInBackground(String... f_url) {
        int count;

        try {

            URL url = new URL(f_url[0]);
            URLConnection conection = url.openConnection();
            conection.connect();

            // download the file
            InputStream input = new BufferedInputStream(url.openStream());
            OutputStream output = new FileOutputStream(path);

            byte data[] …
Run Code Online (Sandbox Code Playgroud)

android downloadfileasync android-internal-storage

1
推荐指数
1
解决办法
3189
查看次数

WebClient.DownloadFileAsync获取不完整的内容

我正在使用WebClient.DownloadFileAsync获取一批文件.但是有些文件不完整,没有例外.

我的问题是,如何在下载的文件未完成时进行标记?没有md5校验和来验证.

代码段是:

using (WebClient client = new WebClient())
{
    Uri sUri = new Uri(sFileLink);
    client.DownloadFileAsync(sUri, myPath);
}
Run Code Online (Sandbox Code Playgroud)

.net c# webclient downloadfileasync

0
推荐指数
1
解决办法
1364
查看次数