protected override async Task GetAndSaveFile(string filename) { await CoursesClient.LazyRefresh(); CoursesClient.AddEvent(DownloadProgressTracker); // we request headers because otherwise the file is first put into memory so we lose the whole point of streams // since we are using ReadAsStreamAsync, nothing is loaded into memory // although we can't use HeadersResponse from previously because that way we can't track progress using (var file = await CoursesClient.SessionClient.GetHeadersAsyncHttp(DownloadUrl)) { using (var fileStream = File.Create(filename)) { using (var content = await file.Content.ReadAsStreamAsync()) { await content.CopyToAsync(fileStream); await fileStream.FlushAsync(); } } } CoursesClient.RemoveEvent(DownloadProgressTracker); }