Untitled

 avatar
unknown
csharp
2 years ago
897 B
0
Indexable
using System;
using System.Net;
using System.Threading.Tasks;

class Program {
    static void Main(string[] args) {
        string[] urlsToDownload = new string[] { 
            "https://example.com/file1.txt", 
            "https://example.com/file2.txt", 
            "https://example.com/file3.txt" 
        };

        // use multiple threads to download the files
        Parallel.ForEach(urlsToDownload, url => {
            DownloadFile(url);
        });

        Console.WriteLine("File download completed successfully.");
        Console.ReadLine();
    }

    static void DownloadFile(string url) {
        string fileName = url.Substring(url.LastIndexOf("/") + 1);
        using (WebClient client = new WebClient()) {
            client.DownloadFile(url, fileName);
        }
        Console.WriteLine("File downloaded successfully: " + fileName);
    }
}