madaxe2023
New member
- Joined
- Apr 9, 2023
- Messages
- 3
- Programming Experience
- 5-10
I'm creating a WPF Splash Screen that should display a progress bar while the background data is being loaded. I want this to be parallel processed.
My first attempt sort of works as long as the same method is being used x number of times.
the second method is closer to what i want but how do i report progress.
thanks
madaxe
My first attempt sort of works as long as the same method is being used x number of times.
the second method is closer to what i want but how do i report progress.
thanks
madaxe
C#:
private Task LoadDataTask(IProgress<ProgressTracker> progress,CancellationToken cancellationToken)
{
ProgressTracker report = new ProgressTracker();
Parallel.ForEach<int>(endPoints, (call) =>
{
results.Add(_configFileBuilderHTTPClient.GetAllAppConfigModelsAsync().Result);
report.percentageComplete = (results.Count * 100) / endPoints.Count;
cancellationToken.ThrowIfCancellationRequested();
progress.Report(report);
});
report.percentageComplete = 100;
progress.Report(report);
return Task.CompletedTask;
}
C#:
private Task LoadDataTask2(IProgress<ProgressTracker> progress, CancellationToken cancellationToken)
{
ProgressTracker report = new ProgressTracker();
List<AppConfigModel>? intResult1 = null;
List<AppConfigModel>? intResult2 = null;
List<AppConfigModel>? intResult3 = null;
Parallel.Invoke(
() => intResult1 = _configFileBuilderHTTPClient.GetAllAppConfigModelsAsync().Result,
() => intResult2 = _configFileBuilderHTTPClient.GetAllAppConfigModelsAsync().Result,
() => intResult3 = _configFileBuilderHTTPClient.GetAllAppConfigModelsAsync().Result
);
return Task.CompletedTask;
}