2011-05-27 76 views
0

我每隔5分鐘使用Web客戶端下載數據,但有時會顯示併發錯誤。WebClient問題

   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); 

    } 

我是初學者,所以上面的代碼看起來很亂。感謝指導,謝謝!

+1

你可以發佈你得到的異常的詳細信息嗎(完整的堆棧跟蹤請)? – 2011-05-27 20:14:44

回答

0

謝謝德魯馬什,解決方案是使用webClient.isbusy標誌。

if(webClient.isbusy == false) 
    webClient.DownloadStringAsync(new Uri(url));