Reputation: 53
File download from HTTP site fails with error,
"System.IO.IOException: The process cannot access the file 'c:\temp\python-3.8.0-amd64.exe' because it is being used by another process".
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();
}
Upvotes: 1
Views: 269
Reputation: 313
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
}
Upvotes: 1
Reputation: 26
Upvotes: 0