随着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) 我正在使用 Flutter 1.10.3 构建应用程序,但无法将图像下载到设备的下载文件夹。
有没有不使用任何第三部分库的选项?