What you should know about Threads in .NET

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.ค. 2024
  • Nobody is using threads directly anymore in the .NET world we all rather rely on asynchronous Tasks which are executed by threads which are managed by the thread pool, so the only useful thing about threads is knowing how they run your async tasks.
    Support my Work 🤝 / raw_coding
    Buy my Courses 📚 learning.raw-coding.dev
    Buy my Merch 🛒 shop.raw-coding.dev
    Join the Community 💬 / discord
    Tweet Tweet 📣 / anton_t0shik
    Tune in LIVE! 🎥 / raw_coding
    #aspnetcore #dotnet #csharp

ความคิดเห็น • 27

  • @denis.akopyan
    @denis.akopyan 5 หลายเดือนก่อน +23

    This is a very important video for understanding threads and async code. I strongly suggest using visuals. I personally love your cog analogy, but images might help the mind focus on understanding the concepts without putting too much effort of visualizing a cog.
    Even a clumsy ms paint picture can go a long way.

    • @eddypartey1075
      @eddypartey1075 5 หลายเดือนก่อน +2

      Exactly! Got the same idea while was watching vid

  • @fieryscorpion
    @fieryscorpion 5 หลายเดือนก่อน +14

    This would have been a great video with some diagrams or animations.
    Felt really hard to follow, so I'll probably have to watch it few more times to understand.

    • @user-tv9sm8bb8w
      @user-tv9sm8bb8w 4 หลายเดือนก่อน +1

      Agree

    • @sergeys5270
      @sergeys5270 4 หลายเดือนก่อน +1

      it would be clearer if there was a simple visual presentation

  • @vedantkoditkar5968
    @vedantkoditkar5968 5 หลายเดือนก่อน +6

    Would be great if you could or already have a video about how such situations can be handled by refactoring the code.

  • @SuperKombain
    @SuperKombain 5 หลายเดือนก่อน

    Thank you so much for a dark IDE theme! Appreciate you've heard my ask 🙏

  • @Jebediah_w
    @Jebediah_w 5 หลายเดือนก่อน

    Love the in depthness of this one.

  • @parkerwarner8688
    @parkerwarner8688 5 หลายเดือนก่อน +1

    Love the video. What would be the case of a blocking task? Or something that would jam the thread and not finish? Trying to think of a real world example

    • @RawCoding
      @RawCoding  5 หลายเดือนก่อน +1

      There shouldn’t be. This tended to happen when people mixed non async synchronisation tools with async code such as locks, which are used inside Semaphore (not slim) ConcurrentBag etc…

  • @charles_kuperus
    @charles_kuperus 5 หลายเดือนก่อน

    That was awesome video About tasks and threads. Would you do a video on configure await equals false vs true?

  • @naitik_
    @naitik_ 5 หลายเดือนก่อน

    One more thing to add to this:
    - Normally, the Task approach is a good thing. It saves the application from hogging all the threads of the machine and juggles small operations on threads. Like one more layer of juggling on a processor. And it protects beginners from messing up with direct threads. Only for advanced level scenarios one may have to deal with direct threads.

  • @_OsamaAmir
    @_OsamaAmir 5 หลายเดือนก่อน +2

    so if tasks are jamming the threads, is it not a bad idea to use a lot of await keywords, if I remember correctly, you told in your async await video that if awaiting is not required, we should just return a Task and manage awaiting higher up the chain of functions,
    my question is that just making, running and returning tasks without using await, do they also block the threads, or do they perform the operation synchronously it is a bit confusing so can you guide on that a bit

    • @RawCoding
      @RawCoding  5 หลายเดือนก่อน +2

      Everytime you write await, you are creating a cog before and after the await, the thread pool will place those cogs on the thread.
      Cogs don’t block, statements such as lock, and getawaitergetresult cause cogs to block.

  • @gustavnilsson6597
    @gustavnilsson6597 4 หลายเดือนก่อน

    Brilliant!

  • @veec1539
    @veec1539 5 หลายเดือนก่อน

    Love the videos, though miss the light mode with shades

  • @thishandleistaken
    @thishandleistaken 5 หลายเดือนก่อน +2

    Something went wrong with the audio and video, it's not synced.

    • @SilverFerrum
      @SilverFerrum 5 หลายเดือนก่อน +6

      Await it

  • @ragtop63
    @ragtop63 5 หลายเดือนก่อน

    Although I understand what you’re trying to illustrate, I feel like the cog analogy isn’t as intuitive as might have first seemed. Also, working visuals would help a lot too.

  • @GrimReaper160490
    @GrimReaper160490 5 หลายเดือนก่อน

    Is it just me or is the audio desynched from the video?

  • @gordonfreimann
    @gordonfreimann 5 หลายเดือนก่อน +1

    can you make video of c# scripting with roslyn?

    • @RawCoding
      @RawCoding  5 หลายเดือนก่อน

      I have a bunch of vids like that on my video looking for anything specific?

  • @wobblejuice
    @wobblejuice 5 หลายเดือนก่อน +7

    the voice is out of sync...

  • @TheJohndward01
    @TheJohndward01 5 หลายเดือนก่อน

    Yay for darkmode!!!

  • @ethanr0x
    @ethanr0x 5 หลายเดือนก่อน

    You need to explain and demonstrate better how ACTUAL threads execute an ACTUAL task with logging the Thread.ID for example before this video can really make sense.
    Now I am left with the idea that different threadpool threads execute different segments of the underlying task state machine but why do they not execute all of it? Why exactly?

  • @Riketta
    @Riketta 4 หลายเดือนก่อน

    Nice beard

  • @ilyahryapko
    @ilyahryapko 5 หลายเดือนก่อน +1

    English is too much of a non-native language for me to listen repeating "cogs" to be honest :)
    Anyways, Anton, your videos are just diamonds in all that junk of modern .net content. Thank you!