-
|
I'm trying to write an application that uses Downloader for multi-threaded downloading. When I attempt to run the following code, the program terminates very quickly (this is definitely not because the download rate is too fast; the bandwidth is approximately 100-190 Mbps). It outputs an empty file. I have confirmed through Neat Download Manager that the target server supports multi-threaded downloading, and I haven't received any error messages in the console. using SuikaiLauncher.Core;
using SuikaiLauncher.Core.Base;
public class Client
{
public async static Task Main()
{
try
{
await Task.Run(async () =>
{
await Download.Start(new List<Download.FileMetaData>()
{
new Download.FileMetaData() {
url = "https://releases.ubuntu.com/24.04.2/ubuntu-24.04.2-live-server-amd64.iso",
path = "./ubuntu.iso"
}
});
}
);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}The implementation code is public class Download
{
public class FileMetaData
{
public string? path { get; set; }
public string? hash { get; set; }
public string? algorithm { get; set; }
public long? size { get; set; }
public string? url { get; set; }
public bool ValidatePathContains(string path)
{
if (this.path.IsNullOrWhiteSpaceF() || path.IsNullOrWhiteSpaceF()) return false;
return Path.GetFullPath(this.path).StartsWith(path);
}
}
private static DownloadConfiguration DlOpt = new()
{
ChunkCount = 64,
MaxTryAgainOnFailover = 10,
MaximumMemoryBufferBytes = 25 * 1024 * 1024,
ParallelDownload = true,
Timeout = 10000,
RangeDownload = true,
MinimumSizeOfChunking = 1024 * 1024,
RequestConfiguration = {
UserAgent = "SuikaiLauncher.Core/0.0.1"
}
};
private static DownloadConfiguration DlOpt0 = new()
{
ChunkCount = 64,
MaxTryAgainOnFailover = 10,
MaximumMemoryBufferBytes = 25 * 1024 * 1024,
Timeout = 10000,
RangeDownload = true,
MinimumSizeOfChunking = 1024 * 1024,
RequestConfiguration = {
UserAgent = "SuikaiLauncher.Core/0.0.1"
}
};
private static void ProgressChangeCallback() {
}
private static DownloadService MuiltDl = new(DlOpt)
{
};
private static DownloadService SingleDl = new(DlOpt0);
public static readonly object FileListLock = new object[1];
public static long TotalFileCount = 0;
public static long CompleteFileCount = 0;
public static async Task Start(List<FileMetaData> DlTasks, CancellationToken? Token = null, int MaxThreadCount = 64)
{
CancellationTokenSource TokenSource = new();
var tasks = DlTasks.Select(dlTask =>
MuiltDl.DownloadFileTaskAsync(
dlTask.url,
dlTask.path
)
);
Task.WaitAll(tasks.ToArray());
}
}Edit: Downloader Version is 3.3.4 .NET Version:8.0.409 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hi @shimoranla, Thanks for reaching out! Based on your description, here are a few suggestions that might help resolve the issue:
using SuikaiLauncher.Core;
using SuikaiLauncher.Core.Base;
public class Client
{
public static async Task Main()
{
try
{
await Download.Start(new List<FileMetaData>
{
new FileMetaData
{
url = "https://releases.ubuntu.com/24.04.2/ubuntu-24.04.2-live-server-amd64.iso",
path = "./ubuntu.iso"
}
});
}
catch (Exception ex)
{
Console.WriteLine($"Download failed: {ex.Message}");
}
}
}
Download.DownloadFileCompleted += (sender, e) =>
{
if (e.Exception != null)
{
Console.WriteLine($"Download error: {e.Exception.Message}");
}
else
{
Console.WriteLine("Download completed successfully.");
}
};This can help you diagnose why the file might be empty or why the task ends abruptly.
If the problem still persists, feel free to open a new issue with more details. |
Beta Was this translation helpful? Give feedback.
Hi @shimoranla,
Thanks for reaching out! Based on your description, here are a few suggestions that might help resolve the issue:
Task.Run(...)for Async Entry PointsUsing
Task.Run(...)in your Main method can suppress exceptions and cause the program to exit prematurely. Instead, await the async method directly. Here's how you can structure your code properly: