gpt4 book ai didi

c# - 完成的异步下载关闭两次而不是一次

转载 作者:行者123 更新时间:2023-11-30 16:06:20 24 4
gpt4 key购买 nike

我的应用程序中有这段代码,允许用户下载最新版本的应用程序。应用程序下载完成后,如果用户想要打开文件位置以查看文件,它会打开一个提示。

但是,该工具会启动两个消息框,而不是只启动一次。我不确定我是否遗漏了什么。

private void BTN_GNV_MouseUp(object sender, MouseButtonEventArgs e)
{
string URLDir = "http://shard.combatkingz.com/downloads/";
string URLName = "DayZ Config Tweak tool v" + Properties.Settings.Default.AvailableVersion + ".exe";
string URLFull = "";
using (WebClient DLWC = new WebClient())
{
URLFull = URLDir + URLName;
GlobalVars.DLPath = System.Environment.CurrentDirectory + "\\" + URLName;
try
{
DLWC.DownloadFileAsync(new Uri(URLFull), GlobalVars.DLPath);
DLWC.DownloadProgressChanged += DLWC_DownloadProgressChanged;
}
catch
{
MessageBox.Show("There was an error downloading the file.", GlobalVars.APPNAME, MessageBoxButton.OK, MessageBoxImage.Error);
#if DEBUG
#else
AddDownloadToDB("Failed");
#endif
}
}
}
void DLWC_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
PB_GNV.Width = (BTN_GNV.Width / 100) * e.ProgressPercentage;
if (PB_GNV.Width == BTN_GNV.Width && e.TotalBytesToReceive == e.BytesReceived)
{
MessageBoxResult nav = MessageBox.Show("New version downloaded. Do you want to navigate to the folder?", GlobalVars.APPNAME, MessageBoxButton.YesNo, MessageBoxImage.Error);
if (nav == MessageBoxResult.Yes)
{
string argument = @"/select, " + @GlobalVars.DLPath;
System.Diagnostics.Process.Start("explorer.exe", argument);
#if DEBUG
#else
AddDownloadToDB("Success");
#endif
}
}
}

最佳答案

我怀疑 DownloadProgressChanged 事件在收到最后一个字节和文件完成时触发。使用 DownloadFileCompleted 事件应该可以解决问题。

关于c# - 完成的异步下载关闭两次而不是一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32412479/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com