-
Notifications
You must be signed in to change notification settings - Fork 145
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
Comments
Blazor is (still) single-threaded, there's no support yet for UI-side async
operations.
…On Tue., May 25, 2021, 5:29 a.m. CornCobs, ***@***.***> wrote:
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: image]
<https://user-images.githubusercontent.com/28252911/119473800-17566900-bd7e-11eb-8889-34f5c2170c53.png>
Output with Task.WhenAll:
[image: image]
<https://user-images.githubusercontent.com/28252911/119473983-4967cb00-bd7e-11eb-9bb4-a44834c7012f.png>
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.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#110>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAK52KCJCGDGG53TDM6ZPN3TPNUX7ANCNFSM45O5WN3A>
.
|
He called out "Blazor Server" in his original post. If he was using client the WaitAll() on Blazor client it would have hung completely. |
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
Blazor version: Blazor Server
I wish to create multiple drawing
Task
which I wait for all at once withTask.WhenAll
like this:Desired output (correctly given by the foreach loop):
Output with
Task.WhenAll
: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.The text was updated successfully, but these errors were encountered: