动态并行任务收集问题 [英] Dynamic Parallel Tasks Collection Question

查看:66
本文介绍了动态并行任务收集问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好专家和社区,

我目前在仪表板场景中有一个要求,在这种情况下,我们有一个可自定义的仪表板,根据用户保存的首选项,用户可以拥有0个或最多15个不同的部分,这些部分最终可以在其仪表板上呈现.每个部分仅显示 有关类别的总数.

I currently have a requirement in a dashboard scenario, where we have a customizable dashboard, where a user can have 0 or up to 15 different sections that can end up rendering on their dashboard, based on their saved preferences. Each section simply displays a count total for the category in question.

由于用户在其仪表板上可以有0个或最多15个不同的部分,所以我只想处理显示的部分的计数,而不想无论如何总是计算15个不同的总数.

Since a user can have 0 or up to 15 different sections on their dashboard, I only want to process the counts for the displayed sections, rather than always compute 15 different totals no matter what.

我们目前将信息传递给具有15个不同的int属性的一个容器类中的UI.然后根据渲染的部分显示它们.现在我要问的是,所有渲染逻辑都已处理,什么是最有效的处理方式 这些都是并行的,但也以动态的方式填充,从而最终填充最终显示的相关属性.

We currently pass the information to the UI in one container class, with 15 different int properties. They then get displayed based on the sections rendered. All of the rendering logic is handled, my question now, is what is the most efficient way to process these in parallel, but also in a dynamic fashion to only populate the relevant properties for what ultimately ends up getting displayed.

DashboardContainer类.

class DashboardContainer..

prop(int)Section1Count

prop (int) Section1Count

prop(n)Section2Count

prop (int) Section2Count

prop(n)Section3Count

prop (int) Section3Count

..等等

DashboardSection类

class DashboardSection

属性(字符串)名称

给出另一个DashboardSections集合,如何动态创建任务列表,然后仅填充与正确的DashboardSection对应的DashboardContainer属性.

Given another collection of DashboardSections, how can I dynamically create a task list, and then only populate the properties of the DashboardContainer that correspond to the right DashboardSection.

例如,我想出了类似的东西..但是我仍然对此没有完全的信心.

For Example I came up with something like this.. but I still am not fully confident in it. 

DashboardContainer container = new DashboardContainer();

DashboardSectionsdashboardSections = GetUserDashboardSections(userId); Parallel.ForEach(dashboardSections,(d)=> { 开关(d.Name) { 情况"Section1": container.Section1Count = Task.Run(()=> Section1Service.getCount()).Result; 中断;

DashboardSections dashboardSections = GetUserDashboardSections(userId); Parallel.ForEach(dashboardSections, (d) => { switch (d.Name) { case "Section1": container.Section1Count = Task.Run(() => Section1Service.getCount()).Result; break;

情况"Section2": container.Section2Count = Task.Run(()=> Section2Service.getCount()).Result; break;

case "Section2": container.Section2Count = Task.Run(() => Section2Service.getCount()).Result; break;

案例"Section3": container.Section3Count = Task.Run(()=> Section3Service.getCount()).Result; 休息; //等,最多15种不同情况

case "Section3": container.Section3Count = Task.Run(() => Section3Service.getCount()).Result; break; // etc for up to 15 different cases

//循环后,将DashboardContainer发送到UI

// After loop, send DashboardContainer to UI

这很好用,并且实际上(在视觉上)表现不错,但是老实说,我不知道这种方式在幕后究竟发生了什么,是否可以优化,或者还好.

This works great, and is actually quite (visually) performant, but I honestly don't know what's really happening behind the scenes when doing it this way, if it can be optimized, or if it's fine.

再次感谢

DPCodesAlot

DPCodesAlot


推荐答案

让我们从您的显示技术开始. WinForms,WPF,UWP,控制台,ASP.NET等?

Let's start with what your display technology even is. WinForms, WPF, UWP, Console, ASP.NET, other?

此后,我们可以告诉您您是否在正确的论坛上,更不用说正确的轨道了.

After that we can tell you if you are even on the right forum, much less the right track.


这篇关于动态并行任务收集问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆