static readonly string DOWNLOAD_URL = "https://installer.demo.accurx.com/chain/4.22.50587.0/accuRx.Installer.Local.msi";
static readonly string DOWNLOAD_FILE = "accuRx.Installer.Local.msi";
public static void Main()
long downloadedBytes = 0;
using (HttpClient client = new HttpClient())
client.DefaultRequestHeaders.Range = new System.Net.Http.Headers.RangeHeaderValue(downloadedBytes, null);
using (Stream contentStream = client.GetStreamAsync(DOWNLOAD_URL).Result,
fileStream = new FileStream(DOWNLOAD_FILE, FileMode.Append, FileAccess.Write, FileShare.None))
byte[] buffer = new byte[1024 * 1024];
while ((bytesRead = contentStream.Read(buffer, 0, buffer.Length)) > 0)
fileStream.Write(buffer, 0, bytesRead);
downloadedBytes += bytesRead;
catch (HttpRequestException)
Console.WriteLine("Network error. Retrying in 2 minutes...");
Thread.Sleep(TimeSpan.FromMinutes(2));
Console.WriteLine($"Download complete. {downloadedBytes} bytes downloaded.");