I need help with this code
WebClient client = new WebClient();
string url = "http://someUrl.com"
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(Convert.ToDouble(18.0));
timer.Start();
timer.Tick += new EventHandler(delegate(object p, EventArgs a)
{
client.DownloadStringAsync(new Uri(url));
//throw:
//WebClient does not support concurrent I/O operations.
});
client.DownloadStringCompleted += (s, ea) =>
{
//Do something
};
You’re using a shared
WebClientinstance and the timer is obviously causing more than one download to occur at a time. Spin up a new client instance each time in theTickhandler or disable the timer so it won’t tick again while you’re still handling the current download.