2012-03-09 2 views
0

wpf에 파일 다운로더를 생성하여 주어진 파일 목록에서 다운로드하고 진행되는 개별 다운로드 진행률 막대를 보여줍니다 .... 목록은 1000 개까지 올 수 있습니다. 파일.WPF에서 http 다중 파일 다운로더 만들기

나는 모든 코드를 가지고 있지만 구체적인 것은 해결되었지만 한 가지로 붙어 있습니다 ... 파일을 대기열에 넣는 방법. 아래의 코드를 고려해

private bool Download(String url, int i) 
     { 
      String FileName = "some location.mp4"; 
      label2.Content = "Downloading : " + ht[current.ToString()].ToString(); 
      progressBar1.Value = 0;    
      try 
      { 
       if (url.Equals(Constants.NotFound)) 
        return false; 

       if (File.Exists(FileName)) 
       {      
        current++; 
        if (current <= total)             
         Download(ht[current.ToString()].ToString(), current); 
        else 
        { 
         this.WindowState = System.Windows.WindowState.Normal; 
         MessageBox.Show("Download Finished"); 
        } 

        return true; 
       } 
       wc.DownloadFileAsync(new Uri(url), FileName);     
       return true; 
      } 
      catch 
      { return false; } 
     } 

는 전체 이벤트를 캡처하기를, 나는 그래서 사건 전체 핸들러를 작성했습니다 :

void wc_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) 
    { 
     current++;    
     if (current <= total) 
      Download(ht[current.ToString()].ToString(), current); 
     else 
     { 
      progressBar1.Value = 100;     
      label2.Content = "Download Finished."; 
      label1.Content = "100 %"; 

      this.WindowState = System.Windows.WindowState.Normal; 
      MessageBox.Show("Download Finished"); 
     } 
    } 

이이 파일 중 어느 것도 이미 다운로드하지 존재하지만 때 될 때 완벽하게 작동 파일이 미리 존재하면 다운로드 함수는 재귀 루프가되어 후속 함수 호출이 반환 될 때까지 값을 반환하지 않으며 1000 개의 비디오를 고려하면 메모리에서 너무 커질 수 있습니다.

그래서이 방법을 피하거나 다른 방법을 사용하면됩니다. ??

그리고 나중에 감사드립니다 .... :)

답변

0

재귀 코드가 있습니다. 시도해보십시오.

+0

답장을 보내 주셔서 감사합니다 ..... 이제 중복 코드가 있지만 다음 파일을 다운로드 할 때 볼 수 있듯이 bcos에 대해 언급 한 코드를 사용할 수 없습니다. 이벤트 완료 처리기 및 나는 그 .... 호출 할 필요가 true 파일을 반환하는 경우 그냥 다음 코드를 종료합니다 .... 따라서 중복 된 코드 .... – user1260042