All of this code is in a class library at the lowest level.
For the code block below should I wrap the entire body of code in a Task.Run(()=>{});
or is there a better way to fire each one of those .GroupParts
? Is there where async Parallel would come into play?
public IGroupedParts GroupParts(GroupOption option)
{
IGroupedParts gParts = new GroupedParts();
if (this.Doors.Count > 0) { gParts.Doors = this.Doors.GroupParts(option); }
if (this.Leafs.Count > 0) { gParts.Leafs = this.Leafs.GroupParts(option); }
if (this.Sidelites.Count > 0) { gParts.Sidelites = this.Sidelites.GroupParts(option); }
if (this.Glass.Count > 0) { gParts.Glass = this.Glass.GroupParts(option); }
if (this.GlassStops.Count > 0) { gParts.GlassStops = this.GlassStops.GroupParts(option); }
if (this.Horizontals.Count > 0) { gParts.Horizontals =this.Horizontals.GroupParts(option); }
if (this.Verticals.Count > 0) { gParts.Verticals = this.Verticals.GroupParts(option); }
if (this.Sills.Count > 0) { gParts.Sills = this.Sills.GroupParts(option); }
if (this.Midrails.Count > 0) { gParts.Midrails = this.Midrails.GroupParts(option); }
...///still more code but omitted
return gParts;
}
---Here is an example of what I am talking about when I say wrap the entire body of code with the Task.Run(()=>{});
public async Task<IGroupedParts> GroupParts(GroupOption option)
{
return await Task.Run(() =>
{
IGroupedParts gParts = new GroupedParts();
if (this.Doors.Count > 0) { gParts.Doors = this.Doors.GroupParts(option); }
if (this.Leafs.Count > 0) { gParts.Leafs = this.Leafs.GroupParts(option); }
if (this.Sidelites.Count > 0) { gParts.Sidelites = this.Sidelites.GroupParts(option); }
return gParts;
});
}
---I do not have a Parallel example that is why I am asking for help...