Тёмный

Keep Your C# Application Smooth using Asynchronous Programming with Async/Await 

Nick Proud
Подписаться 6 тыс.
Просмотров 5 тыс.
50% 1

Asynchronous programming at its most basic level is a way of executing a potentially long running task but doing so in a way that doesn't block the whole program and makes it so that the program is still responsive to events and user input.
In this video, I'll show you how to write asynchronous code in C# using the async and await keywords. I'll use an example of a C# WinForms application that calls a slow API, demonstrating how you can allow the API call to run while still being able to interact with the UI simultaneously.
#dotnet #csharp #code #softwaredevelopment #softwareengineer #asynchronous

Опубликовано:

 

16 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 25   
@manojambhore2772
@manojambhore2772 Год назад
Extremely useful one, thanks Nick. I would request similar content on the exception handling, Task cancellation in functions which are async returning Task.
@nickproudprogrammer
@nickproudprogrammer Год назад
Great suggestion!
@jmischa
@jmischa Год назад
Fantastic stuff! Thank you!
@nickproudprogrammer
@nickproudprogrammer Год назад
Glad you enjoyed it!
@Sedna.Kianfarooghi
@Sedna.Kianfarooghi 7 месяцев назад
Easy pizzy. Thanks. I had forgotten the syntax
@STUPIDYOUTUBE_HIDINGMSGS
@STUPIDYOUTUBE_HIDINGMSGS Год назад
Very useful video. Have you considered creating complete tutorials on C# and other MS-related tech? Maybe create a project of ASP MVC with React, etc. how about that? cheers
@nickproudprogrammer
@nickproudprogrammer Год назад
Good idea. I'll get that on my list
@angel_machariel
@angel_machariel Год назад
I appreciate the clear spoken English lol. You never know these days in the programming world. The button call returns a void, not Task, therefore it cannot be awaited. Is that good practice? May also be not handy during tests or bug hunting.
@nickproudprogrammer
@nickproudprogrammer Год назад
Excellent point 👍
@AllAboutDataTechnology
@AllAboutDataTechnology 9 месяцев назад
good video with clear examples given. Thanks!
@nickproudprogrammer
@nickproudprogrammer 9 месяцев назад
You are welcome!
@neilranada
@neilranada Год назад
Thanks for the excellent walkthrough!
@nickproudprogrammer
@nickproudprogrammer Год назад
My pleasure!
@deanambrox8069
@deanambrox8069 Год назад
Thanks for uploading this video. Could you please demonstrate the async await concept in a c# console application if possible.
@nickproudprogrammer
@nickproudprogrammer Год назад
Concept would be basically the same. You use the async keyword in the signature of any method or function you wish to make asynchronous, and then you can await the code from another async method or function
@scotolivera8207
@scotolivera8207 Год назад
well explained
@adarshpanda6062
@adarshpanda6062 Год назад
Could you make a video explaining these concepts using C++/CLI ?
@nickproudprogrammer
@nickproudprogrammer Год назад
Might look at this in future when I revisit c++ 👍
@angel_machariel
@angel_machariel Год назад
I quickly made something for you: *************************************************************************************************** Per MS Documentation: The await operator suspends evaluation of the enclosing async method until the asynchronous operation represented by its operand completes. The await operator doesn't block the thread that evaluates the async method. When the await operator suspends the enclosing async method, the control returns to the caller of the method. *************************************************************************************************** */ internal class Program { public static async Task DoStuffAsync() { for (int i = 1; i < 6; i++) Console.WriteLine(i); await Task.Delay(2000); return "Done: DoStuffAsync"; } static async Task Main(string[] args) { Task DoStuffTask = DoStuffAsync(); Console.WriteLine("Hehe, lemme sneak in here :)"); await DoStuffTask; Console.WriteLine(DoStuffTask.Result); } }
@tamboleo
@tamboleo Год назад
Thank you! What is the purpose of surrounding your http call with a using statement? I've seen this kind of coding before but not really sure why it's used...
@geoffhirst5338
@geoffhirst5338 Год назад
Usually, the using in the manner is to provide automatic disposal of the object that is created. As Nick says here, the purists might argue about its use here, but the idea of disposal of objects is to avoid memory leaks. 😀
@angel_machariel
@angel_machariel Год назад
It closes the connection (security issue) in this case and marks used resources for cleanup (the system decides when to do that exactly). Using this is a good habit and often indispensable in serious code. Is also used, for example when addressing databases. Very important and good habit!
@tamboleo
@tamboleo Год назад
@@angel_macharielMuch appreciated, I was starting to code back then and now I 've seen it more, do you know any youtube vide that goes through this topic more in depth? Thanks again
@angel_machariel
@angel_machariel Год назад
The using statement is nicely explained on the Microsoft website "using statement - ensure the correct use of disposable objects".' It's not some rocket science to solve, it's more about getting used to it.
@miguelperezs3022
@miguelperezs3022 Год назад
Could u do a video explaining the concepts of parameters in API, I mean with restsharp, how to insert headers, body, authorization and comparing that to postman
Далее
That's NOT How Async And Await Works in .NET!
12:25
Просмотров 22 тыс.
@HolyBaam ультанул в конце 🧨
00:34
Просмотров 302 тыс.
КОГДА МАМА НАШЛА ТЕБЕ НЕВЕСТУ
00:55
How to INCREASE C# Performance using SPAN
10:32
Просмотров 8 тыс.
.NET and C# are in trouble. Here is what I'd do.
10:57
Don't Use Polly in .NET Directly. Use this instead!
14:58
C# Async Await Mistakes | Part 1
10:19
Просмотров 34 тыс.
Stop using async void in C#! Do this instead.
13:12
Просмотров 58 тыс.
Await Async Tasks Are Getting Awesome in .NET 9!
9:24
How to use Async/Await/Task in C#
29:45
Просмотров 75 тыс.
8 await async mistakes that you SHOULD avoid in .NET
21:13
@HolyBaam ультанул в конце 🧨
00:34
Просмотров 302 тыс.