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

Create a different way of using async/await in the AsyncAwait solution #4

Open
marijnz0r opened this issue Aug 1, 2024 · 1 comment

Comments

@marijnz0r
Copy link

First of all I want to thank you for your work invested in this project and creating examples for the community. It has helped me a lot.
I want to suggest an improvement to the AsyncAwait solution.
Currently the only usage of the task-based asynchronous pattern is using a different thread to do work on. I think we can improve the solution by providing an example that uses the async and await keywords without introducing a new thread.

Current way:
await Task.Run(() => bst.MakeBreakfast());

Alternative way:
await bst.MakeBreakfastAsync();

This has the same result: work being done asynchronously and a responsive UI, but without an extra thread.

It requires a certain amount of extra code, but I would love to contribute to the project. Let me know if you would appreciate this.

@grantwinney
Copy link
Owner

Thanks! I appreciate you pointing that out. I made the change in the other two events after that one - btnMultipleThreads_Click and btnMultipleThreadsHeavy_Click - but I think I'll leave the one in btnSeparateThread_Click as-is.

It's been awhile since I wrote this, but making the change there would require changing the signature of the BreakfastSingleThread.MakeBreakfast() method, and I think I was trying to prevent touching it... to show what one could gain with a bare minimum of changes.

grantwinney added a commit that referenced this issue Sep 19, 2024
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

2 participants