How to Report Progress with Async/Await in .NET Core 3

  Рет қаралды 26,303

Brian Lagunas

Brian Lagunas

Күн бұрын

Пікірлер: 131
@rogerpence
@rogerpence Жыл бұрын
It me four hours to find this superb 7 min solution. Thank you, Brian.
@BrianLagunas
@BrianLagunas Жыл бұрын
Thank you so much for watching
@DoctorMGL
@DoctorMGL 6 ай бұрын
why you are soo good at teaching ? dayuuum i swear i'm not just complimenting you , your teaching method is clear and straight to the point which is something we often miss IRL in schools, and also online .
@BrianLagunas
@BrianLagunas 6 ай бұрын
Thank you so much for the kind words. I appreciate you
@kristynoble8848
@kristynoble8848 3 жыл бұрын
Exactly answered my question, and in only 7 minutes. Clear, concise, and simple. I wish all example videos were this clear. Thank you * 1000!
@BrianLagunas
@BrianLagunas 3 жыл бұрын
Thank you for the kind words
@vinodcs80
@vinodcs80 5 ай бұрын
such a complicated concept taught so easily, wow, appreciate it
@bartsworkshop
@bartsworkshop Жыл бұрын
Thank you, this is the most simplistic way of showing progress that i found so far. Please make more videos like this they are awesome!
@BrianLagunas
@BrianLagunas Жыл бұрын
Thank you so much for the kind words. I want to make more videos, I just haven’t had time. My day job is very demanding.
@Rubiole
@Rubiole Жыл бұрын
This is such a nice explanation and relatively easy to follow! Thanks for your contribution to the community
@BrianLagunas
@BrianLagunas Жыл бұрын
Thank you so much for the kind words
@tommyseacat3580
@tommyseacat3580 2 жыл бұрын
Wow, super video. This concept was on a coding interview home exercise and I didn't know how to report. THANK YUUUUU
@BrianLagunas
@BrianLagunas 2 жыл бұрын
You’re very welcome
@TheBishopOfBarton
@TheBishopOfBarton 2 жыл бұрын
Just found this today - what a simple to follow and very helpful tutorial - just implemented the principles in a piece of code and it worked. Thank you!
@BrianLagunas
@BrianLagunas 2 жыл бұрын
Awesome! Great to hear! Thanks for watching
@Zonawanialonnua
@Zonawanialonnua 4 жыл бұрын
Again, everything is very simple. And as you know, everything simple is brilliant! Thanks Brian!
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thank you very much
@kayun-chan-pit8642
@kayun-chan-pit8642 4 жыл бұрын
Greatest example ever. Extremely clear. Let me bow my head for you 3 times. Thank you very much.
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thank you so much for the kind words. Thank you for watching
@haroldpepete
@haroldpepete Жыл бұрын
you have a new subscriber, by the way let me tell you that you do a great job explaining net.core easy and straight to the content
@longuinni
@longuinni 4 жыл бұрын
Great as always. The next episode could be about the cancelationToken. The user start a task but before finish he decides to cancel that task.
@BrianLagunas
@BrianLagunas 4 жыл бұрын
That's a good idea! Thanks for sharing
@kylerbriskey372
@kylerbriskey372 3 жыл бұрын
Amazing. Simple solution and with the aync await, it cleared up my window studder. Thanks!
@BrianLagunas
@BrianLagunas 3 жыл бұрын
Great to hear! Thanks for watching
@NickBullCSharp
@NickBullCSharp 4 жыл бұрын
Fantastic video again Brian. This couldn't have come at a better time as I'm attempting this exact thing at work now to improve user experience :) Also great Key point about Task.Run(). I have the habit of putting a Task.Run in the method implementation. Therefore, thanks for the heads up on that one! :D
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thank you very much for watching.
@julianturner6203
@julianturner6203 4 жыл бұрын
Thanks Brian, you got the best content right now. You are the best
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thank you very much for the kind words.
@dayta2137
@dayta2137 2 жыл бұрын
Excellent content. Short and sweet! Thanks a lot.
@BrianLagunas
@BrianLagunas 2 жыл бұрын
Thanks for watching
@MRJerrod410
@MRJerrod410 11 ай бұрын
Is there something special about Progress that that allows it to update the controls on the UI thread or will any lambda function created on the UI thread hold the thread it was created on in it's closure?
@pleilleur
@pleilleur 2 жыл бұрын
Great explanation, very useful 👍Thanks
@BrianLagunas
@BrianLagunas 2 жыл бұрын
Thank you for watching
@DaviBittencourt
@DaviBittencourt 4 жыл бұрын
Great Brian!! Waiting for more ...
@BrianLagunas
@BrianLagunas 4 жыл бұрын
More videos are coming :)
@udaysuddhala3512
@udaysuddhala3512 4 жыл бұрын
Very clear explanation !! Loved it👌
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thank you very much sir
@septimusseverus252
@septimusseverus252 3 жыл бұрын
I can't thank you enough for this great video
@BrianLagunas
@BrianLagunas 3 жыл бұрын
Thank you so much for watching
@VinuP2023
@VinuP2023 4 жыл бұрын
As usual, awesome explanation :)
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thank you sir
@rodrigocaballerohurtado5367
@rodrigocaballerohurtado5367 4 жыл бұрын
So simple to understand now
@BrianLagunas
@BrianLagunas 4 жыл бұрын
So glad to hear.
@mojizze
@mojizze 4 жыл бұрын
Wow! Best explanation I've seen. Thanks a lot
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thank you very much
@ПавелАлексеев-р7и
@ПавелАлексеев-р7и 2 жыл бұрын
Thank for this video, its very simple but usefull for work !! )
@BrianLagunas
@BrianLagunas 2 жыл бұрын
Thanks for watching
@vaibhavverma7440
@vaibhavverma7440 2 жыл бұрын
perfect answer to my question!
@BrianLagunas
@BrianLagunas 2 жыл бұрын
Great to hear!
@abosqr7029
@abosqr7029 4 жыл бұрын
Thank you so much, this is very useful and easy to understand.
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thank you for watching
@user-mr-m12312
@user-mr-m12312 4 жыл бұрын
So my question is: how can I become as cool as Brian Lagunas? :)
@BrianLagunas
@BrianLagunas 4 жыл бұрын
HAHAHA!!! You're way cooler than me.😀
@raulands
@raulands 4 жыл бұрын
Brilliant, thanks Brian 👍🏻
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thank you very much.
@NK-xw4uu
@NK-xw4uu 3 жыл бұрын
Brian, please can you clarify whether this approach (passing IProgress) of updating progress bar is specifically when we use async/await with Task.Run? Where as if I had used async/await without Task.Run (say for couple of io bound operations in a for loop) then I could directly update the progress bar value (because it's all happening on the same thread)?
@BrianLagunas
@BrianLagunas 3 жыл бұрын
Correct. If you have a task method that reports progress, using calling Task.Run isn't required.
@goodstas
@goodstas 2 жыл бұрын
Thank u for your videos. I have a question. Usually if we work with a threads then you can set any Control only from UI thread. Here u used Progress class which are invoked through a SynchronizationContext instance captured when the instance is constructed and in your example this is UI thread. So in case if we were using different class, it won't work. Am i right?
@JesusAnguloGasco
@JesusAnguloGasco 4 жыл бұрын
Great video Brian!
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thank you so much Jesus
@matteobarbieri2989
@matteobarbieri2989 4 жыл бұрын
I've always used BackgroundWorker and Report progress event. Is the behavior different?
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Background worker is the "old way" of doing background tasks and reporting progress (which still works). If you're using the newer async/await approach, then this is how you would do it.
@fernando.jimenez
@fernando.jimenez 4 жыл бұрын
Maybe it's just me but I've noticed in your latest videos that the audio/video are not in sync. Great video btw. Thank you.
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Yeah, this is a known issue with KZbin. It works fine on some browsers/devices, and the audio is out of sync on other devices/browsers. I've seen this on my Android while it works perfectly on my Desktop. I am not sure how to prevent that from happening.
@GiovanniQuarella
@GiovanniQuarella 4 жыл бұрын
@@BrianLagunas but with your youtube video from twitch it doesn't happen.
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Yeah, its very weird. I tried some different settings on my next video which will be released tomorrow. Hopefully these new setting will fix the problem. Let me know
@francisroshanfernando9806
@francisroshanfernando9806 3 жыл бұрын
you saved my day !!! super
@BrianLagunas
@BrianLagunas 3 жыл бұрын
Great to hear! Thanks for watching
@aldoboell
@aldoboell 3 жыл бұрын
awesome, thats what I needed.
@BrianLagunas
@BrianLagunas 3 жыл бұрын
Great to hear
@osman3404
@osman3404 4 жыл бұрын
I have similar code in my WPF apps but was wondering if the method LoopTheoughNumbers() was doing an IO bound async task, would it still be “best practice” to call it with the Run.Task() ? Tkx again Brian
@BrianLagunas
@BrianLagunas 4 жыл бұрын
You want to use Task.Run to call CPU-bound methods only
@DarkSolidity
@DarkSolidity 2 жыл бұрын
If my code looks like this how would I report progress? using (HttpRequestMessage request = new HttpRequestMessage(method, uri) { HttpClient client = new HttpClient(); Task task = client.SendAsync(request); HttpResponseMessage response = await task; I’ve noticed that when defined like this I don’t have access to task.Run() I see task.RunAsynchronousily though I’ve been trying to adapt several progress reporting methods but I haven’t been able to get any of them to work.
@alhassanmarafa8460
@alhassanmarafa8460 3 жыл бұрын
Hi Brian, this is the best video i have seen about this subject, Thank you. i have one question though. if i choose let's say count = 5, the progress will not go till the end of the bar which i assume is not what we want. No matter the count we should get 100%. Any idea?
@BrianLagunas
@BrianLagunas 3 жыл бұрын
The math in that demo already handles that scenario. The only thing you'll need to do is set the final 100% state when the task has completed since the progress will not be reported on task completion.
@alhassanmarafa8460
@alhassanmarafa8460 3 жыл бұрын
@@BrianLagunas Thanks for the quick reply. I will see how i can manage that. I'm kinda new to this.
@microtech2448
@microtech2448 2 жыл бұрын
How would you do same thing when it is . Net core mbc application and you are uploading large excel file and this file is being processed on separate class library project called from mvc controller? Show progress bar in real time?
@BrianLagunas
@BrianLagunas 2 жыл бұрын
Since it doesn’t sound like your upload method supports reporting progress, you’ll just show an indeterminate progress bar when you start the upload and close it when the upload completes.
@microtech2448
@microtech2448 2 жыл бұрын
@@BrianLagunas Thanks for confirmation
@tkshiv20
@tkshiv20 3 жыл бұрын
Thank you so much.
@BrianLagunas
@BrianLagunas 3 жыл бұрын
Thanks for watching
@knlreiniger
@knlreiniger 3 жыл бұрын
I have a problem; the progressbar only updates at the end of the method. It is worth to mention that the method im trying to run async is located in a seperate cs file.
@knlreiniger
@knlreiniger 3 жыл бұрын
tried moving the method to the xaml.cs file where the caller is located ,still not working
@knlreiniger
@knlreiniger 3 жыл бұрын
nevermind, was my own stupidity, i forgot to put thread sleep, apparently it goes too fast to update :D
@BrianLagunas
@BrianLagunas 3 жыл бұрын
Awesome! I am glad you figured it out.
@MJ-xl5jz
@MJ-xl5jz 2 жыл бұрын
I had that problem with the Textbox. Then I just called .Update at the Textbox right after the change to the .Text Property.
@CHITRANSHSHARMA
@CHITRANSHSHARMA 3 жыл бұрын
Thanks, I used similar in .net framework
@BrianLagunas
@BrianLagunas 3 жыл бұрын
Great 👍
@sarthakchauhan4163
@sarthakchauhan4163 4 жыл бұрын
Great video
@BrianLagunas
@BrianLagunas 4 жыл бұрын
thank you for watching
@mfelipeof
@mfelipeof 3 жыл бұрын
Awesome video Brian, thank you so much for this !! Just one tip about your rule: "Do not use Task.Run in the implementation of the method...": Some situations, like using a nuget package that performs async operations or creating a custom nuget package to use accross many projects, is required return tasks objects and the consumer project use the "await" keyword. One additional question is: How can I report progress when execute a external .exe or any command line, using Process class ? In this case, I don't have a loop or anything like this, you know? The command line can perform a looong time to complete. I can estimate a duration of the command, but I don't know how update the progress bar while the time is passing. I think that is something like a "tick" check in a async task
@iankirkpatrick2022
@iankirkpatrick2022 Жыл бұрын
In order to show a meaningful progress bar, you need an end goal... how long should it take. If the exe you're executing doesn't give you a way to know that you have no way of calculating a percent cause there's nothing to compare current progress to. You're stuck with exactly what you are doing... an estimation based on what you normally see it take. For this reason, you either have to make up an end goal or don't bother with a progress bar cause it'll probably be meaningless to the user. In other words, if the external process doesn't report progress, you are limited in what you can report. It's a black box.
@senadmeskincoding
@senadmeskincoding 4 жыл бұрын
Is it me or the last few videos have an audio delay? Good explanation by the way. Great video.
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Yes, some people have seen an audio delay, but I am unable to. It's really weird and frustrating on my part. I am trying to figure out what could be causing the issue. It's the never ending "it works on my machine" LOL
@sleepingtiger4436
@sleepingtiger4436 2 жыл бұрын
I need an explanation on why it is inefficient? Please explain the "Do not run the task.run in the implementation oof the [async] method"???
@julianturner6203
@julianturner6203 4 жыл бұрын
Brian, can you please tech us how to copy a lot files with sub directories without blocking the UI? Thanks in advance
@BrianLagunas
@BrianLagunas 4 жыл бұрын
That might make for a good video 😀
@julianturner6203
@julianturner6203 4 жыл бұрын
@@BrianLagunas that would be awesome 😁
@BrianLagunas
@BrianLagunas 4 жыл бұрын
@@julianturner6203 Here you go kzbin.info/www/bejne/boGvnXt6m7Ngm9k
@rahulmathew8713
@rahulmathew8713 4 жыл бұрын
Hi Brian, Can you please do a video on creating a user control with dependency property, routed event and to implement commanding with a user control. How to attach a command to handle click event with a user control. Thanks Rahul Mathew
@BrianLagunas
@BrianLagunas 4 жыл бұрын
That's a lot for one video. These would have to be broken down into separate videos. Also, it sounds like you should probably be using a Custom Control not a UserControl.
@rahulmathew8713
@rahulmathew8713 4 жыл бұрын
@@BrianLagunas Hi Brian, I am watching your plural sight. So in that, the course title is given Custom Control. So should I follow that one. Is there is a difference between custom and user control? Please advise Thanks Rahul Mathew
@BrianLagunas
@BrianLagunas 4 жыл бұрын
@@rahulmathew8713 Yes there is a difference. I believe I talk about those differences in the course. Thanks for watching :)
@harsheng
@harsheng 4 жыл бұрын
How to debug Task and threads in better way in c#?
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Great qustion!
@cueware
@cueware 4 жыл бұрын
Hi, thanks for your Video. How I can do that with DI Containers?
@BrianLagunas
@BrianLagunas 4 жыл бұрын
I'm sorry, but I don't understand the question. Do what exactly with a DI container? Can you provide more detail?
@cueware
@cueware 4 жыл бұрын
@@BrianLagunas Thanks for your answer. I mean Dependency Injection Containers like Autofac, Ninject etc... How can i access the Progress Class on the calling class when autofac is automatically injecting the Progress Class? Sorry 4 my bad english...
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Usually you'll register your service class with the container and then the container would automatically inject that service class into the ctor of the class your trying to use it in. Also, don't worry about your English. Its great! I envy anyone that can speak multiple languages.
@cueware
@cueware 4 жыл бұрын
@@BrianLagunas Hello thank you, do you think a video about this would be helpful for many of your followers? I am currently trying to get closer to the solid principles
@BrianLagunas
@BrianLagunas 4 жыл бұрын
I could probably do a video series on the SOLID design principles. Great idea!
@diegoronkkomaki6858
@diegoronkkomaki6858 4 жыл бұрын
Great!
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thank you so much
@gus9822
@gus9822 4 жыл бұрын
Hi. i am loving your videos . Big fan . I have a question regarding "DialogAware". How do i know if a dialog i already open? I don't want to open a dialog 2 times . There is way to ask the dialog service? Thank you
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thank you for watching. It sounds like you'll need to create a custom dialog service that derives from the Prism service, and add the ability to track your dialog instances.
@ievheniiierokhin1677
@ievheniiierokhin1677 4 жыл бұрын
Hm but whats wrong with wrapping implementation of method with task.run, i did it a lot and just like await MyMethod() and i am happy with that, why its better to wrap synchronous method within task.run?
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Here's a great blog post by Stephen Cleary that explains the issue with Task.Run in the method implementation very well: blog.stephencleary.com/2013/11/taskrun-etiquette-examples-dont-use.html
@ievheniiierokhin1677
@ievheniiierokhin1677 4 жыл бұрын
@@BrianLagunas thanks, great post!
@janhendrikschreier
@janhendrikschreier 4 жыл бұрын
@@BrianLagunas Maybe that whole story is worth a video in itself. Steven refers to ASP.net most of the time, so I focussed example might be worth it. At least for me I just got rid of a sexy busy indicator which is replaced by data just being there synchronosly, bamm! So my question would be, if there is some sort of natural tipping point, where you suggest to go async because it is too slow or is it pure try and error when you switch over?
@BrianLagunas
@BrianLagunas 4 жыл бұрын
@@janhendrikschreier I always place the loading of data on a worker thread in my desktop apps. My #1 rule is to keep the UI responsive at all times. Considering the various numbers of unknowns of the end-user system (RAM, processor, cache size, etc), I don't take a chance.
@MrJohn2475
@MrJohn2475 3 жыл бұрын
does this work on ASP.NET?
@BrianLagunas
@BrianLagunas 3 жыл бұрын
There may be some differences, but in general it should work.
@PeterKellner99
@PeterKellner99 4 жыл бұрын
Hi Brian, I've always wanted to do this. Thanks! I'm just wondering though, at the end, when you did your victory dance by grabbing the title bar and dragging it all over you screen, what were you actually demonstrating by doing that? I already believed the the windows async manager works properly. :). Maybe if you pressed a cancel button, then I would have been impressed. Wait, was there a cancel button?
@BrianLagunas
@BrianLagunas 4 жыл бұрын
I was demonstrating that the UI is not being locked up or blocked by the reporting of the progress that is being reported from the long running task. The UI is remaining responsive during the entire process of running the task and updating the UI with the reported progress. There was not a cancel button. Maybe I should add one :)
@magicsmoke0
@magicsmoke0 4 жыл бұрын
Feels like events are used less and less now.
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Technology keeps making things easier for us.
@justinyoung4826
@justinyoung4826 2 жыл бұрын
Unhandled Exception: explicit use of "pretty cool right?" belongs to StyroPyro lol
@BrianLagunas
@BrianLagunas 2 жыл бұрын
I’m guessing that’s another KZbinr that says that a lot? 🤣
@justinyoung4826
@justinyoung4826 2 жыл бұрын
@@BrianLagunas Yes, it's his main catch phrase, but I wasn't being serious at all, just trying to crack a joke in the comments. I appreciate your work man, and your video have been very helpful to me.
@TSHORYUKEN
@TSHORYUKEN Жыл бұрын
but how to update progress from a specific task like API resquests/ long running task ???
@BrianLagunas
@BrianLagunas Жыл бұрын
If the API doesn’t provide a way to report progress you’ll have to use a non-deterministic progress indicator.
C# Yield Return: What is it and how does it work?
15:09
Brian Lagunas
Рет қаралды 57 М.
这是自救的好办法 #路飞#海贼王
00:43
路飞与唐舞桐
Рет қаралды 128 МЛН
That's NOT How Async And Await Works in .NET!
12:25
Codewrinkles
Рет қаралды 26 М.
Which do I use, ConfigureAwait True or False?
6:53
Brian Lagunas
Рет қаралды 38 М.
Why Are You Using Async/Await? (feat. WPF)
6:33
SingletonSean
Рет қаралды 6 М.
Understanding how to use Task and ValueTask
26:59
Microsoft Developer
Рет қаралды 28 М.
Settling the Biggest Await Async Debate in .NET
14:47
Nick Chapsas
Рет қаралды 146 М.
10 C# Libraries To Save You Time And Energy
33:59
IAmTimCorey
Рет қаралды 208 М.
C# Async Yield Return: IAsyncEnumerable will change your life!!!
10:13
Why Asynchronous Web API Endpoints | RESTful | async await
18:10
The Power of Scriptable Objects as Middle-Men
17:41
samyam
Рет қаралды 129 М.
这是自救的好办法 #路飞#海贼王
00:43
路飞与唐舞桐
Рет қаралды 128 МЛН