Тёмный

BEWARE! Async Lazy in C# Is Easy... But Is It Safe? 

Dev Leader
Подписаться 8 тыс.
Просмотров 1,2 тыс.
50% 1

Now that you're using the Lazy class in C# to handle lazy initialization the dotnet way, you're encountering situations where you want to use async await with it. But does the Lazy class support asynchronous operations? And if it does... should we be using it? Let's find out.
For more software engineering videos, check this out:
• 3 Undervalued Software...
Have you subscribed to my weekly newsletter yet? A 5-minute read every weekend, right to your inbox, so you can start your weekend learning off strong:
www.devleader....
Check out more Dev Leader content (including full in-depth articles with source code examples) here:
linktr.ee/devl...
Social Media:
Blog: www.devleader.ca/
Newsletter: www.devleader....
TikTok: / devleader
LinkedIn: / nickcosentino
Threads: threads.net/@dev.leader
Twitter: / devleaderca
Facebook: / devleaderca
Instagram: / dev.leader
GitHub: github.com/nco...
Twitch: / ncosentino
RU-vid: / @devleader
#dotnet #dotnetcore #csharp #lazy #async

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

 

15 окт 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 11   
@DevLeader
@DevLeader Год назад
You can follow along with the companion blog post as well: www.devleader.ca/2023/08/11/async-lazy-in-c-with-great-power-comes-great-responsibility/
@shaznishiraz
@shaznishiraz Год назад
I just started and playing with LAZY and then I was like uh oh, how can I make this work with an async Task & boom so glad I bump into this magnificent well put tutorial, giving it a go right now as I'm watching this!!!! SUBSCRIBED 🔥🔥
@DevLeader
@DevLeader Год назад
Hahaha! That's so awesome to hear 😂 Well thanks for giving my channel a chance! Please feel free to request other topics as you're venturing along! Just drop a comment on a video and I'll see if I can whip something up 🙂
@tamertamertamer4874
@tamertamertamer4874 11 месяцев назад
That might be a stupid question but what are the advantages of putting a Task in a Lazy instead of just using a Lazy ? Also: that’s why you always read error messages :)
@DevLeader
@DevLeader 11 месяцев назад
No stupid questions! It's a safe place 🙂 Personally, for me it's just limited to the benefit of running code in an async await paradigm. If the stuff I want to perform in my lazy method has already been designed for async await, then I can still call it without redesigning things. Yes - we could do things like .Wait() or .Result without using a Task, but those generally are more prone to problems I've found. So TL;DR - if I have async/await code and I want to do an operation once to lazy load something, that's when this fits nicely (just need to be careful for exceptional cases).
@tamertamertamer4874
@tamertamertamer4874 11 месяцев назад
@@DevLeader gotchu thanks :)
@DevLeader
@DevLeader 11 месяцев назад
@@tamertamertamer4874 no worries! Happy to try my best to explain 🙂
@failscript
@failscript Год назад
How I went through a whole .NET bootcamp without ever hearing this, is beyond me!
@DevLeader
@DevLeader Год назад
I try not to be too harsh on bootcamps but I think the majority are just designed to convince you of some expertise in a short time frame ☹️ Hopefully my free content can be helpful to fill some of the gaps for you though! Thanks for the comment 🙂
@pjosip
@pjosip Год назад
I like your channel. Somehow I have a feeling you are spending a bit too much time explaining the obvious. I assume most people know what is await, and if they didn't - this video will not explain it although you are going back on it several times. Nevertheless, thumbs up for the channel!
@DevLeader
@DevLeader Год назад
Great feedback - One of the things I'm paying attention to even outside of video creation is over explaining or explaining the obvious. This is rooted in trying to ensure that I'm able to demonstrate my knowledge to someone. My "defense mechanism" (if I can call it that) is to just keep explaining until I've exhausted how I think I can articulate something. I've been told it's actually helpful in some scenarios (mostly very new folks) but otherwise it's a detriment. So I'm trying my best to improve 🙂 Thanks!
Далее