Wow, as a C# developer for a over a year professionally now, this is something I've honestly never used. It my line of work we just don't have many cpu heavy processing going on. However, in a personal project of my own I've run into this problem. From a developer's standpoint, this was clear, concise and very easy to follow. Bravo!
Very well done, I have been a software engineer for over 35 years, and taught computer science at the university level. Just wanted to send you a shout-out for a well thought out and delivered tutorial.
I like the presentation, but the final solution feels a little convoluted. I understand that the idea is that the BigLongImportantMethod exists and you're trying to wrap it without modifying it. However, you could use the following: private async void button1_Click(object sender, EventArgs e) { label1.Text = "waiting..."; label1.Text = await Task.Run(() => BigLongImportantMethod("Andrew")); } Just mark the click handler as async. Lastly, I think it would have been good to touch on asynchronous I/O. Otherwise, nice work.
Colin Svingen You have a point here , but i guess for beginners like myself I would prefer the breaking down method for more understanding and then we can make things shorter :)
This tutorial set has been amazing.. god.. I've learned so much. This all will come in useful, especially asynchronous logic and lambda expressions! I watched this series at x1.5 speed, mind you; but it's been amazing. Can't wait to bring this to the world.
Hey man, amazing videos! I really loved the way you speak (dinamically) and the content. Just an idea... put in the comments, a link for the previous and next lessons. I came here looking for async but you talk about the "task stuff" and it got my attention, so I should search for the previous lesson. And there you talked about other lessons too, so, a navigation in video descriptions can help a lot! :D keep doing that man, and thanks for the videos
Could you explain the need to write a wrapper? I think you could have simply changed the available function to Private async void BigLongImportantMethodAsync(string name)
This tutorial was awesome. I was having some problems with my app where barcodes were sent via RESTful API to a server and the reading interval is quite fast and there were no time to wait for response. With these tutorials I was able to make robust application which could handle masses of request to server parallel. I previously had a List of threads basically which I polled in a timer. It was quite ok, because it manipulated the UI-components in UI thread. TaskScheduler was the missing link with more OO approach. THANK YOU! All I have to do is this: warehouse.UploadProduct3(Product_REGEXP.Groups[1].ToString(),dg_log);
I was under the impression that just writing a "wrapper" method that calls Task.Start was not the correct way to do things as the original code it is wrapping is not intended to run synchronously.
For some reason, when I do what you have at the end of the Video, my UI is still locked up/not running in the BG, and I cannot change other UI elements on the Main Thread, I believe, like showing an Animated Loading Icon. The Icon never shows, since it's all locked up from this Async stuff, or which SHOULD be Async but isn't... Maybe something else is going on in the BG that's locking up the main UI.
I got it to work, by using a workaround, but still using these methods, if even matters. I had to use a Push Frame Event/Method, to Update the UI. I do this a fraction of the time, in the Loop. So its not killing the Load Perf, and still gives some indication of progress. public object ExitFrame(object f) { ((DispatcherFrame)f).Continue = false; return null; } public void DoEvents() { DispatcherFrame frame = new DispatcherFrame(); Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrame), frame); Dispatcher.PushFrame(frame); } Then in my Loop I can call like, if (pushEventCounter >= imgPaths.Count() / 6) //Push Update to UI every so often, so doesn't slow it down, and shows progress to user... { this.Dispatcher.Invoke((Action)delegate { progressBar1.Value = (progressCounter * 100) / imgPaths.Count(); itemsCount.Text = (progressCounter.ToString() + " Items"); progressCounterBlck.Text = (progressCounter.ToString() + "/" + imgPaths.Count().ToString()); }); DoEvents(); pushEventCounter = 0; }
Hi, Isn't this defeats the purpose of asynchronous/threading programming using Task because you're using AWAIT, then everything beyond that line of code (...StartNew...) will not run? If you want to run your code via threading, why use AWAIT then? Sorry this kinda lost me there.
I don't understand why you need the await keyword to tell the code to "once the execution reaches this line, I cannot continue beyond this line until the task has completed." Isn't that how every single line of code behaves? One line completes, then the next line, etc.
From what I read here, right after the note, docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/await it seems like what it does is takes the lines it's on / it gets and executes them inside a thread, but the lines after it don't execute until after the thread is done. I'm probably wrong about that, but if I'm right, I'd think the actual important line would be async, but everywhere I look they say it doesn't do anything except tell the compiler that there might be an await somewhere. It's really weird, I hope someone explains this.
could someone fet this are you not confucing two concepts 1 Task.Factory (threads) and 2 await async. in other word you could of done this with out Task.Factory
Kindly create your content independent of other video as you are restricting the audience to either fresher or students. But there are multiple people who just want to get some concept clear for them it's hard to understand
Clint Eastwood is the best C# tutorial video out there.
Clear, NIce, Fast and Fun, really the best tutorials ever, thanks so much, It's like reading a 1000 pages book in a couple of hours.
+Julian Carax I agree... So much information in such a short space of time. He is awesome.
Nice! After years, it still remains an excellent option for async await.
Finally the penny dropped. To the point, clear and concise. Keep the tuts coming... Thanks!
Wow, as a C# developer for a over a year professionally now, this is something I've honestly never used. It my line of work we just don't have many cpu heavy processing going on. However, in a personal project of my own I've run into this problem. From a developer's standpoint, this was clear, concise and very easy to follow. Bravo!
You are Awesome Instructor!
All always gives my All Votes to your nice Teaching-Pattern!
Many useful!
Great sharing!
This is just perfect! Thanks for putting this in such a clear and crisp manner.
This was a very instructive and easy to understand tutorial. Thank you Mr. Eastwood.
Very well done, I have been a software engineer for over 35 years, and taught computer science at the university level. Just wanted to send you a shout-out for a well thought out and delivered tutorial.
probably the best c# async await video
Great video. It cleared up for me the difference between using Task and Async/Await.
thank you.
Nice.. thanks for teaching async await 🏇🏇🏇
Haters gonna hate, but this is awesome tutorial.I rarely watch anything above 10 minutes lately, but this was mesmerizing!
best async,await video so far
I like the presentation, but the final solution feels a little convoluted. I understand that the idea is that the BigLongImportantMethod exists and you're trying to wrap it without modifying it. However, you could use the following:
private async void button1_Click(object sender, EventArgs e)
{
label1.Text = "waiting...";
label1.Text = await Task.Run(() => BigLongImportantMethod("Andrew"));
}
Just mark the click handler as async. Lastly, I think it would have been good to touch on asynchronous I/O. Otherwise, nice work.
Colin Svingen You have a point here , but i guess for beginners like myself I would prefer the breaking down method for more understanding and then we can make things shorter :)
Thanks a million, you have solved some of my problems of understanding Async - Await.. Thanks again.
Thank you for this series of videos, very clearly explained!
We need more such nice tutorials.
Thanks, i've learned a lot with this course, and i'll definetly put everything to use! XD
LOTS OF THANKS TO YOUR AWESOME VIDEOS!!!
This tutorial set has been amazing.. god.. I've learned so much. This all will come in useful, especially asynchronous logic and lambda expressions! I watched this series at x1.5 speed, mind you; but it's been amazing. Can't wait to bring this to the world.
Really thanks, you are explaining it very clearly, now i feel much more advanced programmer :)
Hey man, amazing videos! I really loved the way you speak (dinamically) and the content. Just an idea... put in the comments, a link for the previous and next lessons. I came here looking for async but you talk about the "task stuff" and it got my attention, so I should search for the previous lesson. And there you talked about other lessons too, so, a navigation in video descriptions can help a lot! :D keep doing that man, and thanks for the videos
Great video and tutorial!
It looks so simple now :)
Could you explain the need to write a wrapper? I think you could have simply changed the available function to
Private async void BigLongImportantMethodAsync(string name)
Maybe to split it up into smaller chunks to make it more understandable?
microsoft warn against writing async void....
None of my teachers explained so clearly as you.! :D
Awesome. thank you so much
Thank you so much for your excellent video.
Awesome. Thank you!
Great job Clint thank you very much!
Incredible... thanks a lot.
Excellent lessons, I learn a lot.How do you plan a lesson with these easy to understand examples? Do you follow certain books or blogs?
Very awesome tutorial
This tutorial was awesome. I was having some problems with my app where barcodes were sent via RESTful API to a server and the reading interval is quite fast and there were no time to wait for response. With these tutorials I was able to make robust application which could handle masses of request to server parallel. I previously had a List of threads basically which I polled in a timer. It was quite ok, because it manipulated the UI-components in UI thread. TaskScheduler was the missing link with more OO approach. THANK YOU! All I have to do is this: warehouse.UploadProduct3(Product_REGEXP.Groups[1].ToString(),dg_log);
Thank you for your video
FYI, the person uploading these videos doesn't actually own the videos.
+Tech Tadashii-Ching No shit.
+System Void You would think that statement was a no shit statement but if you read the other comments... It's not so obvious for some.
Very clear explanation. Subscribed
It is clear and Nice.Thank You...
Cheers, good video.
Very nice. Would be nice to run at x1.25 speed, some parts use a lot of works for some pretty simple stuff, but nicely explained regardless.
Thank you guy! You are awesome!
Thanx nice lesson
Thank you very much for sharing! :)
I was under the impression that just writing a "wrapper" method that calls Task.Start was not the correct way to do things as the original code it is wrapping is not intended to run synchronously.
What are the advantages of this over using a backgroundworker object?
you are beast ..... thnx 2 u
For some reason, when I do what you have at the end of the Video, my UI is still locked up/not running in the BG, and I cannot change other UI elements on the Main Thread, I believe, like showing an Animated Loading Icon. The Icon never shows, since it's all locked up from this Async stuff, or which SHOULD be Async but isn't... Maybe something else is going on in the BG that's locking up the main UI.
I got it to work, by using a workaround, but still using these methods, if even matters. I had to use a Push Frame Event/Method, to Update the UI. I do this a fraction of the time, in the Loop. So its not killing the Load Perf, and still gives some indication of progress.
public object ExitFrame(object f)
{
((DispatcherFrame)f).Continue = false;
return null;
}
public void DoEvents()
{
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
new DispatcherOperationCallback(ExitFrame), frame);
Dispatcher.PushFrame(frame);
}
Then in my Loop I can call like,
if (pushEventCounter >= imgPaths.Count() / 6) //Push Update to UI every so often, so doesn't slow it down, and shows progress to user...
{
this.Dispatcher.Invoke((Action)delegate
{
progressBar1.Value = (progressCounter * 100) / imgPaths.Count();
itemsCount.Text = (progressCounter.ToString() + " Items");
progressCounterBlck.Text = (progressCounter.ToString() + "/" + imgPaths.Count().ToString());
});
DoEvents();
pushEventCounter = 0;
}
could u plz provide me link about other viedos
seems powerful, but the code looks dirty.
The question is: But can it be easily be used in Unity3D?
thanks man!
works great!
Just gr8. thx.
Good stuff
Hi,
Isn't this defeats the purpose of asynchronous/threading programming using Task because you're using AWAIT, then everything beyond that line of code (...StartNew...) will not run?
If you want to run your code via threading, why use AWAIT then? Sorry this kinda lost me there.
You could use this.Dispatcher.Invoke() to overcome thread affinity
Very nice..but I'm doing all these stuff with threads...Now i think i need to switch to task
Thanks.
Greeaaaat!
I don't understand why you need the await keyword to tell the code to "once the execution reaches this line, I cannot continue beyond this line until the task has completed." Isn't that how every single line of code behaves? One line completes, then the next line, etc.
From what I read here, right after the note,
docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/await
it seems like what it does is takes the lines it's on / it gets and executes them inside a thread, but the lines after it don't execute until after the thread is done.
I'm probably wrong about that, but if I'm right, I'd think the actual important line would be async, but everywhere I look they say it doesn't do anything except tell the compiler that there might be an await somewhere.
It's really weird, I hope someone explains this.
The syntax is still too long-winded for me
could someone fet this are you not confucing two concepts 1 Task.Factory (threads) and 2 await async. in other word you could of done this with out Task.Factory
Thank you sir
Kindly create your content independent of other video as you are restricting the audience to either fresher or students. But there are multiple people who just want to get some concept clear for them it's hard to understand
Can skip the first 10 min
Async should neve be void.