相关疑难解决方法(0)

使用进度条下载异步文件

随着WebClient下载进度的变化,我试图让进度条的进度发生变化.当我startDownload()在下载文件时调用窗口冻结时,此代码仍会下载文件.我希望用户能够在启动屏幕加载时看到进度更改.有没有办法解决这个问题,以便用户可以看到progressBar2变化的进展?

private void startDownload()
{
    WebClient client = new WebClient();
    client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
    client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
    client.DownloadFileAsync(new Uri("http://joshua-ferrara.com/luahelper/lua.syn"), @"C:\LUAHelper\Syntax Files\lua.syn");
}
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
    double bytesIn = double.Parse(e.BytesReceived.ToString());
    double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
    double percentage = bytesIn / totalBytes * 100;
    label2.Text = "Downloaded " + e.BytesReceived + " of " + e.TotalBytesToReceive;
    progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
}
void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
    label2.Text = "Completed";
}
Run Code Online (Sandbox Code Playgroud)

c# asynchronous progress-bar

22
推荐指数
2
解决办法
7万
查看次数

如何使用 Flutter 下载文件并将其存储在 Downloads 文件夹中

我正在使用 Flutter 1.10.3 构建应用程序,但无法将图像下载到设备的下载文件夹。

有没有不使用任何第三部分库的选项?

flutter

10
推荐指数
2
解决办法
2万
查看次数

标签 统计

asynchronous ×1

c# ×1

flutter ×1

progress-bar ×1