Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canvas does not draw with multiple async events waited on via Task.WhenAll #110

Open
CornCobs opened this issue May 25, 2021 · 3 comments
Open

Comments

@CornCobs
Copy link

Blazor version: Blazor Server

I wish to create multiple drawing Task which I wait for all at once with Task.WhenAll like this:

    private async Task DrawStart((int X, int Y) centroid, IEnumerable<(int X, int Y, int Ix)> startPoints)
    {
        await _context.TranslateAsync(centroid.X, centroid.Y);
        await _context.SetFillStyleAsync("blue");
        await _context.FillRectAsync(centroid.X, centroid.Y, 10, 10);
        await _context.SetFillStyleAsync("green");

        // This only draws 1 green rect
        // var drawStartTasks = startPoints.Select(pt =>
        //     _context.FillRectAsync(pt.X, pt.Y, 5, 5));
        // await Task.WhenAll(drawStartTasks);

        // This draws all start points correctly
        foreach (var pt in startPoints)
        {
            await _context.FillRectAsync(pt.X, pt.Y, 5, 5);
        }
    }

Desired output (correctly given by the foreach loop):

image

Output with Task.WhenAll:

image

Adding a .ContinueWith(_ => Console.WriteLine($"Drew point {pt}")) to each task, it appears each Task does complete successfully. Thus I assume the problem is with the canvas and not Blazor.

@mizrael
Copy link
Contributor

mizrael commented May 25, 2021 via email

@RChrisCoble
Copy link

He called out "Blazor Server" in his original post. If he was using client the WaitAll() on Blazor client it would have hung completely.

@mizrael
Copy link
Contributor

mizrael commented May 25, 2021

I missed the "Server" part in the original message, apologies.

However, since the code is running on the HTML canvas, I still suspect it's not doing back/forth with the server and it's trying to run all those tasks on the client instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants