This is my first attempt to get code to run async and I can't tell if it actually is. The function download report does not have an "await" and there is a warning saying it will run synchronously.
I am attempting to download multiple reports at the same time and then zip them all into one file.
The result is as expected but I would like to be certain that the code is actually performing in async.
static async Task Main(string[] args)
{
string folderName = "Batch123";
string fullDir = Path.Combine(ConfigurationManager.AppSettings["path"], folderName);
Directory.CreateDirectory(fullDir);
await RunReports(folderName);
string zipPath = Path.Combine(ConfigurationManager.AppSettings["path"], "Zip", folderName);
Directory.CreateDirectory(zipPath);
ZipFile.CreateFromDirectory(fullDir, Path.Combine(fullDir, zipPath, "CRAs.zip"));
}
private static async Task RunReports(string folderName)
{
string[] dunsToProcess = new string[] {"d1"
,"d2"
,"d3"
};
await Task.WhenAll(dunsToProcess.Select(i => DownloadReport(i, folderName)));
}
private static async Task DownloadReroport(string DUNS, string folderName)
{
NetworkCredential cred = new NetworkCredential(ConfigurationManager.AppSettings["networkUser"]
, ConfigurationManager.AppSettings["networkPassword"]);
string fullPath = Path.Combine(ConfigurationManager.AppSettings["path"], folderName, string.Format("CRA for DUNS {0}.pdf", DUNS));
WebClient wc = new WebClient();
wc.Credentials = cred;
wc.DownloadFile(@"http://xxxxxxx&pcDUNS=" + DUNS
, fullPath);
}
I hope it is right as it will be the basis of a lot of other changes. If not, can you point out what I am doing wrong.
Feel free to ridicule anything with my code!!! I have had no c# training at all.
Thank you.