好吧,我在这里不知所措。我正在尝试下载一个 jar 文件,然后制作一个运行它的批处理文件。我以前可以用我的代码下载这个文件一次,但现在完成的事件触发(我认为,因为它里面的代码运行。对不起,我是 C# 的新手。)但没有下载文件。我添加了一个只有下载代码的新按钮,文件在那里,但它只是显示为 0KB。我当前的代码甚至没有出现在 Fiddler 中。我使用 IP 地址跳过 DNS 检查,并将代理设置为空。(我在某处读到这样做会阻止它挂起。我想。这是关于网络代理自动检测的东西。)我可以验证下载链接(除非你需要它,否则我不会在这里显示)是真实的并且只需在网络浏览器中打开文件即可下载文件。反正,
WebClient wc1 = new WebClient();
wc1.DownloadFileCompleted += new AsyncCompletedEventHandler(wc1_DownloadFileCompleted);
wc1.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc1_DownloadProgressChanged);
if (cmboboxVersion.SelectedText == ...)
{
stsprgsbar.Style = ProgressBarStyle.Continuous;
stslblStaus.Text = "Downloading files...";
wc1.DownloadFileAsync(new Uri(...), @txtboxFolder.Text + "\\jarfile.jar");
FileStream fs = new FileStream(@txtboxFolder.Text + "\\batfile.bat", FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(...);
sw.Close();
fs.Close();
}
else if (cmboboxVersion.SelectedText == ...)
{
stsprgsbar.Style = ProgressBarStyle.Continuous;
stslblStaus.Text = "Downloading files...";
wc1.DownloadFileAsync(new Uri(...), @txtboxFolder.Text + "\\jarfile.jar");
FileStream fs = new FileStream(@txtboxFolder.Text + "\\batfile.bat", FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(...);
sw.Close();
fs.Close();
}
else
{
stsprgsbar.Style = ProgressBarStyle.Continuous;
stslblStaus.Text = "Downloading files...";
wc1.DownloadFileAsync(new Uri(...), @txtboxFolder.Text + "\\jarfile.jar");
FileStream fs = new FileStream(@txtboxFolder.Text + "\\batfile.bat", FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(...);
sw.Close();
fs.Close();
}
}
public void wc1_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
stsprgsbar.Value = e.ProgressPercentage;
}
public void wc1_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
string BatPath = @txtboxFolder.Text + "\\batfile.bat";
stsprgsbar.Style = ProgressBarStyle.Marquee;
stslblStaus.Text = "Generating files...";
ProcessStartInfo pro = new ProcessStartInfo(BatPath);
//pro.CreateNoWindow = true;
Process.Start(pro);
}