private static async Task DownloadFileAsync(DownloadOption option) { var output = option.Output ?? ""; output = Path.GetFullPath(output); Console.WriteLine($"Download url = {option.Url}"); Console.WriteLine($"Output = {output}"); try { var loggerFactory = LoggerFactory.Create(builder => { }); var logger = loggerFactory.CreateLogger <SegmentFileDownloader>(); var progress = new Progress <DownloadProgress>(); var obj = new object(); DownloadProgress downloadProgress = null; progress.ProgressChanged += (sender, p) => { lock (obj) { downloadProgress = p; } }; bool finished = false; long lastLength = 0; DateTime lastTime = DateTime.Now; _ = Task.Run(async() => { while (!finished) { lock (obj) { if (downloadProgress == null) { continue; } Console.Clear(); Console.WriteLine($"Download url = {option.Url}"); Console.WriteLine($"Output = {output}"); Console.WriteLine( $"Process {downloadProgress.DownloadedLength * 100.0 / downloadProgress.FileLength:0.00}"); Console.WriteLine($"{downloadProgress.DownloadedLength}/{downloadProgress.FileLength}"); Console.WriteLine(); Console.WriteLine($"{(downloadProgress.DownloadedLength - lastLength) * 1000.0 / (DateTime.Now - lastTime).TotalMilliseconds / 1024 / 1024:0.00} MB/s"); lastLength = downloadProgress.DownloadedLength; lastTime = DateTime.Now; foreach (var downloadSegment in downloadProgress.GetCurrentDownloadSegmentList()) { Console.WriteLine(downloadSegment); } } await Task.Delay(500); } }); var file = new FileInfo(output); var url = option.Url; var segmentFileDownloader = new SegmentFileDownloader(url, file, logger, progress); await segmentFileDownloader.DownloadFile(); finished = true; } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(e); Console.ResetColor(); } }