Parallel conflict.

I upload images to the cloud Parallel execution:

// Make a TaskFactory that will use the UI thread context
var uiFactory = new TaskFactory(TaskScheduler.FromCurrentSynchronizationContext());

Parallel.ForEach(FinalFileNames,
    new ParallelOptions { MaxDegreeOfParallelism = 4 },
    path =>
    {
         count++;
         /* Calculate percentage of upload done */
         double iPercentDone = (int)(((float)count / iTotalFiles) * 100);

        // Send the progress report to the UI thread.
        uiFactory.StartNew(() =>
        UploadProgress.Value = iPercentDone;

        LblProgress.Content = count.ToString(CultureInfo.InvariantCulture)
                               + " file(s) uploaded from " + iTotalFiles +
                     " file(s)";
                        }
       });

The problem I am facing is that the user interface is blocked when I do this. The reason seems to work on the same topic.

If I complete this Parallel.ForEach in "Task.Factory.New", this will result in asynchronous calls, which is not my requirement.

Please let me know how I can fix the user interface block problem and also not make async calls.

+4
source share

Source: https://habr.com/ru/post/1533146/


All Articles