从HTTP站点下载文件失败,并显示错误
“ System.IO.IOException:该进程无法访问文件'c:\ temp \ python-3.8.0-amd64.exe',因为它正在被另一个进程使用”。
url = "http://ip:43/installer/python-3.8.0-amd64.exe"
Uri uri = new Uri(url);
filename = uri.Segments[uri.Segments.Length - 1];
installer_path = $@"c:\Temp\{filename}";
using (var client = new WebClient())
{
client.DownloadFile(url, installer_path);
client.Dispose();
}
答案 0 :(得分:1)
client.DownloadFileCompleted += WcOnDownloadFileCompleted;
private static void WcOnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
if (!e.Cancelled && e.Error == null)
{
//async download completed successfully
}
handle.Set(); // in both the case let the void main() know that async event had finished so that i can quit
}
答案 1 :(得分:0)