Example #1
0
        public static async System.Threading.Tasks.Task Test()
        {
            string url = "https://speed.hetzner.de/100MB.bin";

            // url = "https://speed.hetzner.de/1GB.bin";
            // url = "https://speed.hetzner.de/10GB.bin";

            using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient()
            {
                Timeout = System.TimeSpan.FromDays(1)
            })
            {
                using (System.IO.Stream stream = System.IO.File.OpenWrite(@"D:\foo.bin"))
                {
                    System.Progress <float> cb = new System.Progress <float>(
                        delegate(float value)
                    {
                        System.Console.WriteLine("Progress: {0}%", value);
                    }
                        );

                    await client.DownloadAsync(url, stream, cb, System.Threading.CancellationToken.None);
                }
            }
        }