我使用web客户端每隔5分钟下载一次数据,但有时会显示并发错误。
TimerCallback call = down;
temp = new Timer(call);
temp.Change(1000, System.Threading.Timeout.Infinite);
public void down(object obj)
{
if(webflag == true)
webClient.DownloadStringAsync(new Uri(url));
webflag = false;
}
private void FeedsDownloaded(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
// some processing
}
webflag = true;
temp.Change(5000, System.Threading.Timeout.Infinite);
}我是初学者,所以上面的代码看起来一定很混乱。感谢指导,谢谢!
发布于 2011-05-28 11:57:46
谢谢你Drew Marsh,解决方案是使用webClient.isbusy标志。
if(webClient.isbusy == false)
webClient.DownloadStringAsync(new Uri(url));https://stackoverflow.com/questions/6155854
复制相似问题