Click here to Skip to main content
15,893,508 members
Home / Discussions / C#
   

C#

 
GeneralRe: Looking for feedback and contributions to database project Pin
BillWoodruff24-Oct-21 23:02
professionalBillWoodruff24-Oct-21 23:02 
GeneralRe: Looking for feedback and contributions to database project Pin
jschell23-Dec-21 5:34
jschell23-Dec-21 5:34 
GeneralRe: Looking for feedback and contributions to database project Pin
Michael Sydney Balloni23-Dec-21 11:21
professionalMichael Sydney Balloni23-Dec-21 11:21 
QuestionHow to get Millions of files from folder and bulk insert in database Pin
Ankur B. Patel16-Oct-21 1:10
Ankur B. Patel16-Oct-21 1:10 
AnswerRe: How to get Millions of files from folder and bulk insert in database Pin
Eddy Vluggen16-Oct-21 3:10
professionalEddy Vluggen16-Oct-21 3:10 
GeneralRe: How to get Millions of files from folder and bulk insert in database Pin
Richard MacCutchan16-Oct-21 4:00
mveRichard MacCutchan16-Oct-21 4:00 
GeneralRe: How to get Millions of files from folder and bulk insert in database Pin
Eddy Vluggen16-Oct-21 4:18
professionalEddy Vluggen16-Oct-21 4:18 
GeneralRe: How to get Millions of files from folder and bulk insert in database Pin
Ankur B. Patel16-Oct-21 4:59
Ankur B. Patel16-Oct-21 4:59 
GeneralRe: How to get Millions of files from folder and bulk insert in database Pin
Gerry Schmitz16-Oct-21 11:04
mveGerry Schmitz16-Oct-21 11:04 
AnswerRe: How to get Millions of files from folder and bulk insert in database Pin
OriginalGriff16-Oct-21 6:43
mveOriginalGriff16-Oct-21 6:43 
AnswerRe: How to get Millions of files from folder and bulk insert in database Pin
Michael Sydney Balloni16-Oct-21 17:36
professionalMichael Sydney Balloni16-Oct-21 17:36 
AnswerRe: How to get Millions of files from folder and bulk insert in database Pin
jschell24-Oct-21 6:50
jschell24-Oct-21 6:50 
QuestionPredicateBuilder Question Pin
Kevin Marois15-Oct-21 5:24
professionalKevin Marois15-Oct-21 5:24 
AnswerRe: PredicateBuilder Question Pin
Eddy Vluggen15-Oct-21 14:44
professionalEddy Vluggen15-Oct-21 14:44 
QuestionTask.WhenAll ConfigureAwait Question Pin
Kevin Marois14-Oct-21 12:57
professionalKevin Marois14-Oct-21 12:57 
AnswerRe: Task.WhenAll ConfigureAwait Question Pin
Richard Deeming14-Oct-21 23:15
mveRichard Deeming14-Oct-21 23:15 
GeneralRe: Task.WhenAll ConfigureAwait Question Pin
Kevin Marois15-Oct-21 4:53
professionalKevin Marois15-Oct-21 4:53 
GeneralRe: Task.WhenAll ConfigureAwait Question Pin
Richard Deeming15-Oct-21 5:59
mveRichard Deeming15-Oct-21 5:59 
GeneralRe: Task.WhenAll ConfigureAwait Question Pin
Kevin Marois15-Oct-21 6:29
professionalKevin Marois15-Oct-21 6:29 
GeneralRe: Task.WhenAll ConfigureAwait Question Pin
Kevin Marois15-Oct-21 8:08
professionalKevin Marois15-Oct-21 8:08 
GeneralRe: Task.WhenAll ConfigureAwait Question Pin
Richard Deeming17-Oct-21 21:58
mveRichard Deeming17-Oct-21 21:58 
If you have a large or unknown number of tasks, or you don't care about the value (if any) returned by the tasks, then Task.WhenAll is usually the simplest option. But it's not required to get multiple tasks running at the same time.

If you're just loading data and setting the properties on your view-models, you generally don't need to be running on the UI thread. If you're updating a collection, you might need to use BindingOperations.EnableCollectionSynchronization[^] to enable updates from a background thread; but most property changes on a view-model will just work from any thread.

But as you discovered, you will need to be running on the UI thread to show another view. Therefore, you probably want to split the job into multiple tasks: a top-level task which kicks off the loading tasks, awaits Task.WhenAll to wait for them to finish (without using ConfigureAwait), and then displays the dialog; and multiple sub-tasks which load the data and update the view-model, which can use .ConfigureAwait(false).

Eg:
C#
private async Task LoadProjects(VendorsByProjectAndJobReportViewModel vm)
{
    var projects = await Task.Run(() => AppCore.BizObject.GetProjectHeaders(AppCore.AppCompany.Id).ToList()).ConfigureAwait(false);
    vm.Projects = projects;
}

private async Task LoadJobs(VendorsByProjectAndJobReportViewModel vm)
{
    var jobs = await Task.Run(() => AppCore.BizObject.GetJobListHeaders(AppCore.AppCompany.Id).ToList()).ConfigureAwait(false);
    vm.Jobs = jobs;
}

private async Task ShowVendorsByProjectAndJobReport()
{
    WaitIndicatorVisibility = Visibility.Visible;
    
    var dialogVm = new VendorsByProjectAndJobReportViewModel();
    var tasks = new List<Task>
    {
        LoadProjects(dialogVm),
        LoadJobs(dialogVm),
    };
    
    await Task.WhenAll(tasks); // NB: No "ConfigureAwait" here
    DialogResultEx result = DialogService.ShowDialog(dialogVm, typeof(MainWindowView));
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Task.WhenAll ConfigureAwait Question Pin
Kevin Marois18-Oct-21 4:01
professionalKevin Marois18-Oct-21 4:01 
QuestionCodility fails to compile even though it compiles in VS code? Pin
Cliff ludo13-Oct-21 6:41
Cliff ludo13-Oct-21 6:41 
AnswerRe: Codility fails to compile even though it compiles in VS code? Pin
BillWoodruff13-Oct-21 17:11
professionalBillWoodruff13-Oct-21 17:11 
Generalpass array to function Pin
Cliff ludo12-Oct-21 23:04
Cliff ludo12-Oct-21 23:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.