So I'm getting an error
WebClient does not support concurrent I/O operations.
I know the error comes because I'm using the WebClient at the same time. Can anyone help regarding this issue?? I would like to make my code download one at a time.
Here is my code.
public partial class Form1 : Form
{
WebClient webClient = new WebClient();
private DownloadLink[] downloadLinks = new DownloadLink[]
{
new DownloadLink("congestions-manifesting-in-rtd/?post=5782", @"D:\\Market Data 2022\\RTD\\Congestions Manifesting in RTD\\Congestions-Manifesting-in-Rtd" ),
new DownloadLink("security-limits-used-in-rtd/?post=5756", @"D:\\Market Data 2022\\RTD\\Security Limits Used in RTD\\Security-Limits-Used-in-Rtd" ),
new DownloadLink("rtd-hvdc-schedules/?post=5770", @"D:\\Market Data 2022\\RTD\\RTD HVDC Schedules\\Rtd-Hvdc-Schedules" ),
};
private void DOWNLOAD_LINKS_Click(object sender, EventArgs e)
{
foreach (DownloadLink downloadLink in downloadLinks)
{
DateTime startDate = dateTimePicker1.Value;
System.Threading.Timer timer = new System.Threading.Timer(RunRtdAsync, new TimerDownloadArgs(downloadLink, startDate), 0, 3000);
}
}
private async void RunRtdAsync(Object state)
{
TimerDownloadArgs downloadArgs = (TimerDownloadArgs)state;
string formattedDate = downloadArgs.startDate.ToString("yyyy-MM-dd");
string downloadPath = "https://www.iemop.ph/market-data/" + downloadArgs.downloadLink.path + "&sort=&page=1&start=" + formattedDate + "%2000:00&end=" + formattedDate + "%2023:59";
if (await HttpClientHelper.DoesFileExist(downloadPath))
{
webClient.DownloadFile(downloadPath, downloadArgs.downloadLink.filePath + "_" + formattedDate + ".zip");
downloadArgs.startDate = downloadArgs.startDate.AddDays(1);
}
}