0

My problem is that I have this upload queue, and when I'm putting x number amount of files in the queue it only shows me the last file because the for loop goes around too fast.

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

}

I've tried to use

Task.Delay(1)

System.Theading.Thread.Sleep(1)

to work it around, but they haven't worked. So what I basically need is to wait percentage to go 100 and then go to next index.

Community
  • 1
  • 1
Fuppetia
  • 47
  • 4

1 Answers1

-1

Try using While condition to hold the code.

for (i = 0; i < uploadFileList.Count; i++)
{
    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;                       

    while (percentage < 100)
    {
        continue;
    }

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

       }
}
changsiang
  • 157
  • 6
  • Placing execution in a tight spin in order to wait for something is a really bad idea. This will burn CPU/battery for no good reason. – spender Jun 04 '18 at 11:05
  • Placing the GUI thread in a tight spin is even worse because it will hang the GUI. – spender Jun 04 '18 at 11:08
  • I agree this is a bad idea. The requirement of the question is that the user wish to upload multiple files and wants the code to wait for each file upload to reach 100 percent before moving on to the next line of code. Ideally, it would be better to make the upload task async and not hold up the GUI. – changsiang Jun 04 '18 at 11:14