Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Asynchronous reading XML in Blazor

$
0
0

I have problem while trying to read XML data from string asynchronous in Blazor. It's just freeze browser for couple seconds while reading. I wonder how to do it asynchronous to get nice progress for validation.Here is my implementation.

<RadzenButton Visible="true" ButtonStyle="ButtonStyle.Light" Click="@(async () => await ValidateAsync())">Waliduj Async</RadzenButton>    private async Task ValidateAsync()    {        await using var timer = new Timer(_ => InvokeAsync(() => StateHasChanged()));        timer.Change(TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500));        progress = 0;        try        {            XmlReaderSettings settings = new XmlReaderSettings();            StringReader stringReader = new StringReader(xmlData);            settings.Async = true;            using (XmlReader reader = XmlReader.Create(stringReader, settings))            {                while (await reader.ReadAsync())                {                    progress++;                }            }        }        finally        {            StateHasChanged();        }    }

P.S. This is my first stackoverflow question so feel free to correct me if construction of question is incorrect


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>