简体   繁体   English

Blazor - 异步渲染大数据

[英]Blazor - asynchronously render big data

on my Razor page I have an svg container.在我的 Razor 页面上,我有一个 svg 容器。

Inside of the svg I draw the circles.在 svg 内部我画了圆圈。
It could be thousands of circles in the SVG. SVG 中可能有数千个圆圈。

<svg>
  @foreach (var pixel in GetPixels())
  {
     <circle class="pixel" cx="@pixel.CoordinateX" cy="@pixel.CoordinateY" />                  
    }
</svg>

and GetPixels is和 GetPixels 是

 IEnumerable<Pixel> GetPixels()
        {
            var progress = 0;
            float oldPercent = 0;
            foreach (var p in Result.Pixels)
            {
                yield return p;

                var progressPercent = (float)Math.Ceiling(progress * 1F / (Result.TotalItems) * 100F);
                if (progressPercent % 1 == 0 && oldPercent != progressPercent)
                {
                    Js.InvokeVoidAsync("updateProgress", progressPercent);
                    oldPercent = progressPercent;
                }

                progress++;

            }
        }

The backend iteration works very fast, the problem occurs when there foreach statement is complete and the browser is trying to render thousands of these circles, so it literally hanging for a while.后端迭代工作非常快,当 foreach 语句完成并且浏览器试图渲染数千个这样的圆圈时,就会出现问题,因此它实际上会挂起一段时间。

I would like to implement some batch load of the circles, when after specific amount of circles I rerender the svg (let say 1000 circles - output to SVG and show partially a picture).我想实现一些圆圈的批量加载,当在特定数量的圆圈之后我重新渲染 svg(比如说 1000 个圆圈 - output 到 ZCD15A75C26008696637B31A3F0DE4)并显示部分图片。

Could you please suggest what would be the better way of doing it?你能建议什么是更好的方法吗?

I have no answer for you regerding the current release version but if you look at .net 5 they have solved this (in the upcoming preview).我无法回答您当前的发布版本,但如果您查看 .net 5,他们已经解决了这个问题(在即将发布的预览版中)。 Look at this video of the .net Community Standup and go to 50m50s and you will see an implementation of your question using tables.观看.net Community Standup和 go 到 50m50s 的这段视频,您将看到使用表格实现您的问题。

So IF you can use .net5 preview or you can wait till the end of the year when it is released I suggest you use that approach.因此,如果您可以使用 .net5 预览版,或者您可以等到年底发布,我建议您使用这种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM