Тёмный

Have You Ever Signaled async/await Progress in These Three Ways? 

Zoran Horvat
Подписаться 30 тыс.
Просмотров 11 тыс.
50% 1

Tasks have greatly simplified synchronization and data marshaling, which we can use quite effectively to transfer progress information back from the running task. There is always a ton of synchronization code at the back, but we shall never have to write that code. That is the beauty of working with .NET tasks.
But the story does not end at the basic scenario. Have you ever thought of what data can be the progress? Is that only the byte count or a percentage, or can we use some less conventional pieces of information? I will ask you to approach this video with an open mind. I will then show you how to hijack the built-in progress marshaling mechanism to inform the outer world about all kinds of events that happen during the task's execution. That will be useful, but above all - it will be fun.
Download source code ► / zoranhorvat
Join Discord server with topics on C# ► codinghelmet.c...
Enroll course Beginning Object-Oriented Programming with C# ► codinghelmet.c...
Subscribe ► / @zoran-horvat
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
👨 About Me 👨
Hi, I’m Zoran, I have more than 20 years of experience as a software developer, architect, team lead, and more. I have been programming in C# since its inception in the early 2000s. Since 2017 I have started publishing professional video courses at Pluralsight and Udemy and by this point, there are over 100 hours of the highest-quality videos you can watch on those platforms. On my RU-vid channel, you can find shorter video forms focused on clarifying practical issues in coding, design, and architecture of .NET applications.❤️
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
⚡️COPYRIGHT NOTICE:
The Copyright Laws of the United States recognize a “fair use” of copyrighted content. Section 107 of the U.S. Copyright Act states: “Notwithstanding the provisions of sections 106 and 106A, the fair use of a copyrighted work, including such use by reproduction in copies or phono records or by any other means specified by that section, for purposes such as criticism, comment, news reporting, teaching (including multiple copies for classroom use), scholarship, or research, is not an infringement of copyright." This video and our RU-vid channel, in general, may contain certain copyrighted works that were not specifically authorized to be used by the copyright holder(s) but which we believe in good faith are protected by federal law and the Fair use doctrine for one or more of the reasons noted above.
#csharp #dotnet #objectorientedprogramming

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

 

28 сен 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 44   
@sebastianszafran5221
@sebastianszafran5221 4 месяца назад
You are a phenomenon I've found lately. Besides the rich content I especially love the passion for coding coming out of your voice!
@WoonCherkLam
@WoonCherkLam 4 месяца назад
As always, Zoran makes everything look effortless. :)
@faridfereidoony227
@faridfereidoony227 4 месяца назад
This is not code, this is art. Thank you sir.
@ivandrofly
@ivandrofly 3 месяца назад
Exactly
@erikgrundy
@erikgrundy 4 месяца назад
Never heard of progress before - seems really cool!
@ivandrofly
@ivandrofly 3 месяца назад
Very useful for UI programming winform/wpf
@okcharles7
@okcharles7 4 месяца назад
Amazing. Your video always holds me down to the beginner, which is a great joy in boring day lives. This video leads me to MS blog titled "Async in 4.5: Enabling Progress and Cancellation in Async APIs". It would be highly appreciated if you could recommend a better or up-to-date one.
@zoran-horvat
@zoran-horvat 4 месяца назад
I read a few articles, but they were nothing special. However, be aware that TPL is a decade old and any article you find will still be accurate from the Tasks point of view.
@bogdanpavlovic3456
@bogdanpavlovic3456 4 месяца назад
He is a legend! Cheers Mr Z ! :)🍺🍻🍺
@ucretsiztakipci6612
@ucretsiztakipci6612 4 месяца назад
Cool content mate!
@kabal911
@kabal911 4 месяца назад
Very nice video. Interestin stuff 👍
@CRBarchager
@CRBarchager 4 месяца назад
Very nice explaination. What system are you running this on. I tried to replicate the code and the progress was about 10 times slower than your video. When reducing to the size of fil from 700 to 70 I got about the same result (runtime) as in the video.. Running this code in Vistual Studio gives alot of warnings like CA1068: Method should take CancellationToken as last parameter in the FileServices class. I know you have some videoes on naming but what's your take on parameter ordering? Thank you again, Zoran.
@zoran-horvat
@zoran-horvat 4 месяца назад
Ah parameter ordering! I have already mentioned that issue in an earlier video and I will get back to it again. I am forcing functional design, where it is common to configure the operation first, and then to parameterize it. It works oppositely from object-oriented design. I guess I will have to talk more about that... Speed in my demo comes mostly from SSD. Slower the disk, slower the operation. The CPU is mostly idle. It is interesting that I couldn't reproduce the clog in the last demo on my MacBook M2 Pro, but had to run it in a virtual machine on a 3-4 years old Windows desktop to cause the performance issue.
@ievheniiierokhin1677
@ievheniiierokhin1677 4 месяца назад
Nice!
@willemtoerien
@willemtoerien Месяц назад
They way you do your video's and how you make a story of it is simply beautiful. I love watching your videos!!! Thank you!
@codingbloke
@codingbloke 4 месяца назад
Very nice. TIL Progress class and interface. I really must get back to the habit of RTM.
@henry-js
@henry-js 4 месяца назад
Thank you for this! No frills, no boilerplate, just clean code with succinct explanation 😊
@goranvrbancic9689
@goranvrbancic9689 4 месяца назад
Zorane, samo jedna riječ : hvala !
@DanielGarciaPampin
@DanielGarciaPampin 3 месяца назад
Thank you so much for this video! I just found your channel and everything is so well explained and useful. I have one question. Within the "try" block we await for the "GenerateTextFile()" method to end. Makes sense, we don't want the program to end before finishing the task. However, why do we await "keyboard" and "ticker" tasks at the "finally" block? We just canceled them, they aren't supposed to be running anymore, are they?
@ivandrofly
@ivandrofly 3 месяца назад
6:00 - throttling progress report. Thumbs up for that
@zoran-horvat
@zoran-horvat 3 месяца назад
There was a joke back in my C++ days, over 20 years ago: You know you did a good job when you have to throttle your code or everything else will die.
@ivandrofly
@ivandrofly 3 месяца назад
@@zoran-horvat ahah
@SanyaBane
@SanyaBane 4 месяца назад
Great example. Thanks for video
@phoenixishere
@phoenixishere 4 месяца назад
you are truly underrated my man
@dr.angerous
@dr.angerous 4 месяца назад
He's really not.
@LuizADRMarques
@LuizADRMarques 4 месяца назад
This one was particularly useful. I had used Progress before, but not in these ways...
@RualddeBruyn
@RualddeBruyn 4 месяца назад
Stahp, you're convoluting my mind. This is awesome.
@AdNecrias
@AdNecrias 4 месяца назад
Really cool, thanks.
@JonathanPeel
@JonathanPeel 4 месяца назад
So, is progress kind of similar to Subject? Does Progress do anything Subject wouldn't?
@zoran-horvat
@zoran-horvat 4 месяца назад
From what I know, Subject's primary purpose is to be observable, which doesn't care about threads. Progress, on the other hand, is spanning Tasks. It is aware of the synchronisation context (if any) within which it is constructed, and it will use that context to execute the callback. It will only run on a random thread if there was no synchronisation context when it was constructed. Therefore, Progress is safe for use in UI applications, but it is also guaranteed to work safely in any other multithreaded application. Even though use cases may look similar, these two classes are not interchangeable.
@АлександрРужников-з9м
I am a bit confused about the statement "work safe in other multithreaded applications". As far as I understand if sc is null, report callback will be simply pushed to thread pool. There is no thread safe guaranty beetween two subsequent report callback calls and they have a chance to run simultaneously.
@zoran-horvat
@zoran-horvat 4 месяца назад
@@АлександрРужников-з9м The guarantee is required to marshal the underlying value from one thread to another. Once done, the callback is all you have, and it only executes on one thread.
@АлександрРужников-з9м
@@zoran-horvat Yes, I am agreed that progress arguments are safely marshalled. However my point is two subsequent callback calls are not thread safe in general case. If the callbacks share some state, access to it must be synchronized, because the thread pool does not give sequential execution guarantee for two subsequently queued callbacks. In your example, console is that shared state. There is a chance you see 48% status update before 47%.
@zoran-horvat
@zoran-horvat 4 месяца назад
@@АлександрРужников-з9м I see your point, but that is what synchronization contexts are meant for. If you play by the book, the Progress object will just work. For example, using the progress object to share a mutable state is not played by the book, and so is when the multithreaded application's main thread operates outside the synchronization context.
@joga_bonito_aro
@joga_bonito_aro 4 месяца назад
This video feels like a fever dream 😂
@zoran-horvat
@zoran-horvat 4 месяца назад
Is that good or bad? :)
@joga_bonito_aro
@joga_bonito_aro 4 месяца назад
@@zoran-horvat in this case, good ;)
@GerardJaryczewski2023
@GerardJaryczewski2023 4 месяца назад
This morning I was looking for a raw code like this, I didn't want to use e.g. Spectre Console, which is awesome BTW, and... then I have found this treasure. Thank you, @zoran-horvat, today you are my Santa Clause.
@zoran-horvat
@zoran-horvat 4 месяца назад
Any time!
Далее
Master the Design of Functional Behavior in C#
19:17
Просмотров 11 тыс.
17 Pieces of C# Syntax That Make Your Code Short
12:41
11 ming dollarlik uzum
00:43
Просмотров 625 тыс.
That's NOT How Async And Await Works in .NET!
12:25
Просмотров 23 тыс.
Master the Design of Functional Types in C#
17:53
Просмотров 16 тыс.
Avoid This Common Mistake in DDD Modeling
10:17
Просмотров 9 тыс.
Nothing is really cool in Kotlin
7:43
Просмотров 6 тыс.
Await Async Tasks Are Getting Awesome in .NET 9!
9:24
Favor Declarative Design and Cure That Code Clutter
10:29
Manage Nulls Like a Boss and Never Fail!
21:43
Просмотров 13 тыс.
C# Records Are Functional - Use Them That Way!
10:55
Просмотров 12 тыс.
5 Design Patterns That Are ACTUALLY Used By Developers
9:27