对于循环等待,直到其他任务完成

时间:2018-06-04 10:53:01

标签: c# wpf

我的问题是我有这个上传队列,当我在队列中放入x个数量的文件时,它只显示最后一个文件,因为for循环过快。

for (i = 0; i < uploadFileList.Count; i++)
{
    if (percentage == 100)
    {
     projects_tab.IsEnabled = true;
     wait_for_upload_text.Visibility = Visibility.Hidden;
     ModelUploadTXT.Text = "Upload done!";
     FooterProgressBar.Value = 0;
     FooterProgressBar.Foreground = Brushes.LimeGreen;
     cancel_upload_model_button.Visibility = Visibility.Hidden;
     SelectedFileText.Text = "Choose model(s) to import!"; 

     try
       {
       uploadClient.Dispose();
       }
     catch (Exception asd)
       {

       }
     }
     else
         {
          choosedProjetName = uploadFileList[i];
          ShowHome();
          cancel_upload_model_button.Visibility = Visibility.Visible;
          ModelUploadTXT.Text = "Uploading " + choosedProjetName + FooterProgressBar.Value.ToString("f0") + " % " + (bytesIn / 1000000).ToString("f2") + "Mb /" + (totalBytes / 1000000).ToString("f2") + "Mb";
          FooterProgressBar.Foreground = Brushes.Orange;                       
         }

}

我试过用

  

Task.Delay(1)

     

System.Theading.Thread.Sleep(1)

要解决它,但它们没有奏效。所以我基本上需要的是等待百分比变为100,然后转到下一个索引。

1 个答案:

答案 0 :(得分:-1)

尝试使用While条件来保存代码。

debounce