nwss
31-01-2024, 00:50
Добрый день.
С#, Net Framework 4.5
Хочу создать консольное приложение которое загрузит файл с отображением процесса загрузки.
using System;
using System.ComponentModel;
using System.IO;
using System.Net;
public class Program
{
public static void Main()
{
new Program().Download("https://github.com/deemru/Chromium-Gost/releases/download/121.0.6167.85/chromium-gost-121.0.6167.85-windows-386.zip");
}
public void Download(string remoteUri)
{
string FilePath = Directory.GetCurrentDirectory() + "/temp/" + Path.GetFileName(remoteUri);
using (WebClient client = new WebClient())
{
if (!Directory.Exists("temp"))
{
Directory.CreateDirectory("temp");
}
Uri uri = new Uri(remoteUri);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(Extract);
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgessChanged);
client.DownloadFileAsync(uri, FilePath);
}
}
public void Extract(object sender, AsyncCompletedEventArgs e)
{
Console.WriteLine("File has been downloaded.");
}
public void ProgessChanged(object sender, DownloadProgressChangedEventArgs e)
{
Console.WriteLine($"Download status: {e.ProgressPercentage}%.");
}
}
Но загрузка не происходит. Ошибок не дает. Создает папку темп, в ней название целевого файла с весом 0 байт и закрывается.
В таком виде работает, но хотелось бы отображение процесса загрузки.
using System;
using System.Net;
namespace test
{
internal class Program
{
static void Main1(string[] args)
{
string URI = "https://github.com/deemru/Chromium-Gost/releases/download/121.0.6167.85/chromium-gost-121.0.6167.85-windows-386.zip";
using (var client = new WebClient())
{
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
client.DownloadFile(URI , "chromium-gost-121.0.6167.85-windows-386.zip");
}
Console.WriteLine("Готово");
Console.ReadKey();
}
}
}
Подскажите, что не так с первым кодом?
С#, Net Framework 4.5
Хочу создать консольное приложение которое загрузит файл с отображением процесса загрузки.
using System;
using System.ComponentModel;
using System.IO;
using System.Net;
public class Program
{
public static void Main()
{
new Program().Download("https://github.com/deemru/Chromium-Gost/releases/download/121.0.6167.85/chromium-gost-121.0.6167.85-windows-386.zip");
}
public void Download(string remoteUri)
{
string FilePath = Directory.GetCurrentDirectory() + "/temp/" + Path.GetFileName(remoteUri);
using (WebClient client = new WebClient())
{
if (!Directory.Exists("temp"))
{
Directory.CreateDirectory("temp");
}
Uri uri = new Uri(remoteUri);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(Extract);
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgessChanged);
client.DownloadFileAsync(uri, FilePath);
}
}
public void Extract(object sender, AsyncCompletedEventArgs e)
{
Console.WriteLine("File has been downloaded.");
}
public void ProgessChanged(object sender, DownloadProgressChangedEventArgs e)
{
Console.WriteLine($"Download status: {e.ProgressPercentage}%.");
}
}
Но загрузка не происходит. Ошибок не дает. Создает папку темп, в ней название целевого файла с весом 0 байт и закрывается.
В таком виде работает, но хотелось бы отображение процесса загрузки.
using System;
using System.Net;
namespace test
{
internal class Program
{
static void Main1(string[] args)
{
string URI = "https://github.com/deemru/Chromium-Gost/releases/download/121.0.6167.85/chromium-gost-121.0.6167.85-windows-386.zip";
using (var client = new WebClient())
{
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
client.DownloadFile(URI , "chromium-gost-121.0.6167.85-windows-386.zip");
}
Console.WriteLine("Готово");
Console.ReadKey();
}
}
}
Подскажите, что не так с первым кодом?