Async vs Thread | C# Interview Questions with Answers | Csharp Interview Questions

Поделиться
HTML-код
  • Опубликовано: 25 дек 2024

Комментарии •

  • @questpondvideos
    @questpondvideos  3 года назад +4

    Software Architecture Interview Questions : ruclips.net/video/AtTgcbLOqMM/видео.html
    25+ OOPS Interview Questions : ruclips.net/video/u99wAoBjDvQ/видео.html
    30 Important C# Interview Questions : ruclips.net/video/BKynEBPqiIM/видео.html
    20+ SQL Server Interview Questions : ruclips.net/video/SEdAF8mSKS4/видео.html
    10+ Power BI Interview Questions : ruclips.net/video/Cozc9WNBRt4/видео.html
    20 MSBI Interview Questions : ruclips.net/video/Nw_sHEKnOUE/видео.html
    SQL Server Joins : ruclips.net/video/KTvYHEntvn8/видео.html
    SQL Step by Step - ruclips.net/video/uGlfP9o7kmY/видео.html
    Angular Step by Step Tutorial for Beginners : ruclips.net/video/-9VcW7MBDs8/видео.html
    25 Angular Interview Questions : ruclips.net/video/-jeoyDJDsSM/видео.html
    25 Important ASP.NET Interview Questions : ruclips.net/video/pXmMdmJUC0g/видео.html
    35 Important JavaScript Interview Questions : ruclips.net/video/Zb4dPi7CANU/видео.html
    20 MySQL Interview Questions : ruclips.net/video/9hfjC-BpY20/видео.html
    5 MSBI Interview Questions : ruclips.net/video/5E815aXAwYQ/видео.html
    20 PHP Interview Questions : ruclips.net/video/1bpNSynUrl8/видео.html

  • @MicroftHunter
    @MicroftHunter 5 лет назад +4

    They have similarity of background worker but the difference with the two is async await is not using a separate thread,but they are markers which mark code positions from where control should resume after a task or thread completes.

  • @dustinzhang293
    @dustinzhang293 4 года назад +19

    I think the point is that async/await pattern itself doesn't necessarily imply multithread. It means the code behind it is non-blocking. Whether there is a new thread really depends on the actual code (cpu bound or not)

  • @MaheshSingh-ev8yh
    @MaheshSingh-ev8yh Год назад +2

    Hi Shiv Sir. I am following your video when I have started my career 10 years back but still your videos r so fresh and so amaze, really pin point the basics.👏

  • @lynndemarest1902
    @lynndemarest1902 3 года назад +14

    This is true as far as it goes, but I think threads are necessarily created to do the async work. These threads are created not in the application, but in the dotnet framework or the operating system, which is why they're not visible in Visual Studio. When a request is made to read a website, for example, the async state machine is created by the dotnet framework and a call is made to the network adapter's driver. The driver's work is done on a separate thread which when it returns picks up a thread from the OS thread pool to continue work on the next part of the state machine. Right?

  • @shervilgupta92
    @shervilgupta92 2 года назад +1

    Just Switched from Java to C# and was scratching my head learning the async concept. This really cleared the confusion. Thank you so much !

    • @frankabignale2176
      @frankabignale2176 2 года назад

      why would you? java has more jobs and high paying ones too.

    • @shervilgupta92
      @shervilgupta92 2 года назад

      @@frankabignale2176 well wasn't my decision to make, my current company uses c#

    • @frankabignale2176
      @frankabignale2176 2 года назад

      @@shervilgupta92 what do you work on?

  • @ssssss1738
    @ssssss1738 3 года назад +2

    great explanation! As a node js developer here, this video somehow teaches me the nature of "async", even though node js using libuv and event loop, but the underlying idea is kind same. Thank you!

  • @UserSam832
    @UserSam832 2 года назад +1

    You should given Doctorate in C# Shiv. Ur knowledge and passion to help others is invaluable

  • @BigBhardwaj
    @BigBhardwaj 5 лет назад +4

    A big shout out to you, Shiv ! and sincerely hope e-(ager) learners remain 'synchronized' for more 'context' and content on Multi-threading etc. !

  • @shaikhussain_ece
    @shaikhussain_ece Год назад

    I'm In Loop mode of your videos which are simple and clear

  • @wpelfeta
    @wpelfeta Год назад

    Thanks for this video. I remember being taught that Async/Await was used for mitigating I/O blocking, but a lot of my peers talk about it as if it were multithreading. So it's good to verify what I had learned. I think one point of confusion is probably that Async/Await is in the System.Threading namespace, which makes it seem like it's related to threading.

  • @vladimirkuznetsov3601
    @vladimirkuznetsov3601 6 месяцев назад

    Much better than some of Microsoft dev's talks on async/await!

  • @expertreviews1112
    @expertreviews1112 6 лет назад +7

    Brilliant video. Can't appreciate enough

  • @swarupfule3557
    @swarupfule3557 3 года назад +2

    Why there is just 835 likes. Definitely this is best style of teaching.

  • @mehdiichkarrane8808
    @mehdiichkarrane8808 4 года назад +1

    this is some very valuable content. thank you for the clear explanation

  • @being_aslam_tiger
    @being_aslam_tiger 2 года назад

    Greatest Explained 👑💕

  • @minezgio3175
    @minezgio3175 2 года назад

    Really good video. Finally I was to able to understand this concept.

  • @1989vinayak
    @1989vinayak 3 года назад +2

    Beautifully explained, Thanks a lot,
    i have a query, if async doesn't create new thread, then who executes the 5- 6 code block as main thread process would be completed by that time

  • @ruler5408
    @ruler5408 3 года назад

    It's an awesome video and crystal clear on asynchronous working. Thank You

  • @dibbyo456
    @dibbyo456 4 года назад

    Everything is crystal clear now. Awesome video.

  • @shayamsandhya
    @shayamsandhya 5 лет назад +3

    Good video but this seems to be true only when you run a task which does't require a CPU bound operation such as delay if you are running a loop inside a task then it create a thread for it

  • @vrajeshbadgujar
    @vrajeshbadgujar 7 месяцев назад

    Great Explanation!

  • @amoltiwari8371
    @amoltiwari8371 Год назад

    Thank you shiv sir to explain in depth

  • @31337flamer
    @31337flamer 3 года назад

    very informative .. made some things clear and showed some things that i was not aware of. thanks for sharing!

  • @mohsinmemon3362
    @mohsinmemon3362 2 года назад

    great explanation . thanks for making this video.

  • @amreshchandra4098
    @amreshchandra4098 4 года назад

    I never write comment on youtube.But for you i m writting.Very nice explaind.

  • @chevn9260
    @chevn9260 4 года назад +1

    Thank you, I have learned to use async

  • @SzTz100
    @SzTz100 2 года назад

    Awesome explanation

  • @taqikhan5418
    @taqikhan5418 День назад

    We heard that TASK is a wrapper on thread which internally uses thread, and Tasks are often used with async await making this question in mind.

  • @shubhamchoudhary5957
    @shubhamchoudhary5957 11 месяцев назад

    Sir After wathcing your video my threading conceopt and the async concept is clear.

  • @simonsullivan8344
    @simonsullivan8344 2 года назад

    Brilliant made it clear

  • @mirali829
    @mirali829 Год назад

    Thanks I 've got a deeper concept of it

  • @nandanthareja
    @nandanthareja 4 года назад

    Commendable explanation

  • @barteknikliborc7109
    @barteknikliborc7109 2 года назад

    greate explenation, thanks!

  • @TheSmoothPower
    @TheSmoothPower 5 лет назад

    Excellent video, thank you Sir

  • @konnelius
    @konnelius 5 лет назад +1

    Thanks a lot for a very informative explanation :)

  • @Sopiro
    @Sopiro 4 года назад +1

    What a good explanation! I got to know a lot. thank you!

  • @xybersurfer
    @xybersurfer 2 года назад

    async can increase the performance of your application when doing I/O Bound tasks. for example by doing web requests, while waiting for other web requests. but i agree that async can't increase the performance of CPU Bound tasks, as far as i understand it. but it would be nice if async used all available cores, because i really like how little it changes the structure of code. thanks for looking into those thread IDs

  • @sony642
    @sony642 5 лет назад

    Really worth to watch... appreciated!!

  • @artak9439
    @artak9439 28 дней назад

    To avoid blocking the main thread, it must either perform context switching or create a new thread, there is no other option I think.

  • @rukmininaik987
    @rukmininaik987 5 лет назад

    Thank you soo much sir for such a wonderful explanation. This video was indeed so much helpful. Got to know many new things.

  • @ktvideos1219
    @ktvideos1219 5 лет назад

    Superb explanation!

  • @mihailomarcetic2516
    @mihailomarcetic2516 2 года назад

    Gread video !!!!!

  • @sohaibalvi4410
    @sohaibalvi4410 3 года назад +1

    Worker Thread is a Synchronization "Thread that connected the callback and main thread" right sir?

  • @johnnguyen1655
    @johnnguyen1655 4 года назад

    brilliant tutorial!!!!!!!!!!!!!!!

  • @unknownunknown-qx3gu
    @unknownunknown-qx3gu 5 лет назад +8

    Not accurate since async calls does use threads but those threads aren't created as normal threads. Async uses the .NET thread pool to execute asynchronously, that is the reason why new threads aren't visibly created.

    • @questpondvideos
      @questpondvideos  3 года назад

      Even back ground threads are seen in Debug threads nothing comes as such. Yes as its software there would be some thread but the CALLER DOES NOT CREATE THREAD. And what if it was hardware ACK then no threads. Threads will be there or not depends its CPU bound or not.

  • @impostersyndromedev
    @impostersyndromedev 5 лет назад

    Excellent video! Love your code samples.

  • @victory4vivek1
    @victory4vivek1 6 лет назад +1

    SPK sir
    So what should be case in .NET Core? As it is a console application. Whenever we are using async-await, will it create new threads? As we just saw in case of Console application?

    • @questpondvideos
      @questpondvideos  6 лет назад

      In all console application context is a problem. Winforms , WPF have multiple UI so has context funda. Console application is just one UI so no context is created as such.

  • @psycho.2u
    @psycho.2u 3 года назад

    19:56
    May be Console.Read() was blocking the thread...??
    So when u press enter remaining got executed. Not sure. Just a guessing

  • @faeez4722
    @faeez4722 4 года назад

    Amazing

  • @MukeshSharma-ru3ho
    @MukeshSharma-ru3ho 4 года назад

    well explained , thank you

  • @wonseoklee80
    @wonseoklee80 2 года назад

    So async is kind of abstract term whereas thread is a concrete concept. Async can implement thread but also it can use state machine, event loop, timer interrupt or whatever it can make the situation async.

    • @questpondvideos
      @questpondvideos  2 года назад

      No Async is not abstract term. Threads and Async are different

    • @wonseoklee80
      @wonseoklee80 2 года назад

      @@questpondvideos Thread used to used for asynchrony too. When we use render thread that renders html, AI image generation, photoshop project, and DAW projects, it not only makes better perfomance but also achiving concurrency as well. We can do this without async keyword.

  • @deepeng37
    @deepeng37 2 года назад

    Can you please explain .ConfigureAwait(false) of Async method ?
    Is it creating a background thread for asynch method?

  • @thesuperiorman8342
    @thesuperiorman8342 5 лет назад +1

    I sub'd. Such a good explanation.

  • @pankajsingh-eg9hm
    @pankajsingh-eg9hm 5 лет назад

    Excellent sir

  • @gaoping7743
    @gaoping7743 5 лет назад

    really good explain.

  • @ritikamanchanda9723
    @ritikamanchanda9723 4 года назад

    Very nicely explained, I have a question though
    What happens when we use ConfigureAwait(false) with async/await. Does it executes on another thread?

    • @AmitChoudhary10
      @AmitChoudhary10 4 года назад +7

      By default, when you use async/await, it will resume on the original thread that started the request. However, if another long-running process currently has taken over that thread, you will be stuck waiting for it to complete. To avoid this, you can use a method called ConfigureAwait with a false parameter. When you do, this tells the Task that it can resume itself on any thread that is available instead of waiting for the thread that originally created it.

    • @ritikamanchanda9723
      @ritikamanchanda9723 4 года назад

      Thanks @@AmitChoudhary10 for clearing my doubt.

    • @lynndemarest1902
      @lynndemarest1902 3 года назад +1

      If you don't care which thread picks up the state machine then ConfigureAwait(false) is appropriate. Some have said it should be the default, since it is more often needed than not.

  • @stalera
    @stalera 5 лет назад

    why don't you add the statemachine detail video url in the description. Or did I miss it?

  • @vamsikumar_n
    @vamsikumar_n 5 лет назад

    super sir

  • @battuhant
    @battuhant 11 месяцев назад

    if we write a code that does a lot of work for example a for loop instead of task.delay. will the code still not produce threads more than one?

  • @jeetucobra
    @jeetucobra 2 года назад

    Sir can you help me when i using async then my Request.context is getting null

  • @lamnguyen2106
    @lamnguyen2106 4 года назад

    thanks

  • @ziaasad2
    @ziaasad2 5 лет назад

    plz ans me ??
    Suppose that you have to load 2 files in parallel in a WPF C# application, now you have two techniques to load files either use threads or use Async Task.
    You need to choose one method to load files, Give at least two solid reasons for choosing one method over the other.

    • @GauravChaudhary09
      @GauravChaudhary09 5 лет назад +1

      if performance is not needed, you can use async which is more suitable for I/O and API calls

    • @questpondvideos
      @questpondvideos  4 года назад

      Do visit www.questpond.com and do email questpond@questpond.com to get queries clear.

  • @mdora3983
    @mdora3983 5 лет назад

    As far as i understand, when thread context changes then it is change the thread of first starting. am i right?

  • @calaiarasan7318
    @calaiarasan7318 5 лет назад

    here 7 and 8 also should be in thread id 4.correct ?

    • @ziv4545
      @ziv4545 5 лет назад

      no, it returns to main thread and executes code 7 and code 8. 20 seconds later it runs on another thread code 5 and code 6.

  • @mrityunjayahiremath3951
    @mrityunjayahiremath3951 5 лет назад

    Please make a full course video on Power BI

    • @questpondvideos
      @questpondvideos  4 года назад

      Thanks and noted the same. Do visit www.questpond.com

  • @vinodreddy1722
    @vinodreddy1722 4 года назад

    Where that async task runs,I case of threading task runs in thread t8?

  • @Kooshad1
    @Kooshad1 3 года назад +1

    link to part 1: ruclips.net/video/8Je1W82vwYM/видео.html

  • @abid777ful
    @abid777ful 5 лет назад

    I am just ,why it's not created a separate thread in the application you demonstrated in the beginning? But its created new thread in the same console application you demonstrated at the end. Confused

    • @questpondvideos
      @questpondvideos  5 лет назад

      Its because of context , we have talked about the same in the video. Do relook once again.

    • @abid777ful
      @abid777ful 5 лет назад

      Thank you very much Sir for replying. Yes I got it, context is lost in the end application. And for resuming where it left it creates that one.
      Your videos are very simple to understand, helpful ,informative and detailed.
      Its saves our lot of time from searching the same online to explore the same.
      You are doing great job for all of us.
      Huge Respect and Thanks to you Sir.

  • @jigarshah1438
    @jigarshah1438 4 года назад +1

    Hi you said that async method work on main thread only and it doesn't create new (you emphasize on this word) thread behind the scene.
    I was going through other video and I found your explanation and their explanation have different view. Here is the link of that video ruclips.net/video/Kfs84d7jaT8/видео.html
    Pls let me know if I have miss understood other video's explanation.
    Thanks.

  • @Wynell
    @Wynell 2 года назад

    I don't really understand it. In the beginning you said that async doesn't use threads, but later in the video you showed that it actually does. What am I getting wrong?

    • @questpondvideos
      @questpondvideos  2 года назад

      yes the main thread does not:-) . The async process can create threads or can be hardware process....

    • @user-nk9ez6ly5s
      @user-nk9ez6ly5s 2 года назад

      Actually I was also in confusion. But what sir was trying to say is the Main thread doesn't create threads, the Task is handled by TPL, which uses threads from thread pool , on this thread pool thread all this state machine stuff runs. Am I right Shiv Sir?

    • @questpondvideos
      @questpondvideos  2 года назад

      @@user-nk9ez6ly5s yes the CALLER does not create thread thats the catch.

  • @InCircle
    @InCircle 4 года назад

    Hi Questond, the display of the video has incorrect spelling for async,

  • @HimalayaGarg
    @HimalayaGarg 4 года назад

    async free the main thread to continue next statements

  • @lazycyclone
    @lazycyclone 2 года назад

    at 19.50 you say you dont know what happened you pressed enter and it appeared. that shows you do not understand ansync/await in c#. still trying to teach.

    • @questpondvideos
      @questpondvideos  2 года назад

      Great way of proving your point by insulting a teacher who has been teaching C# for decade.
      So So coming to your point i have explained that new thread comes for switching the context please watch the further part of video.

  • @IvarDaigon
    @IvarDaigon 4 года назад +17

    this is a terrible explanation of threads and async. awaiting async does use the threadpool which creates threads as needed. There is no guarantee that your code will run on a separate thread when you wait an async method but it can if the main thread is busy. What you are doing in your demo is running SomeMethod synchronously on the main thread by NOT awaiting it. If you run FXCop code analyzer on our code you will get a warning explaining this. If you await SomeMethod and run it in your for loop 1000 times and put a synchronous operation like Task.Delay(1000).Wait() inside the method you will see 999 threads created and an exception because a C# application cannot spawn more than 1000 threads (total) by default.

    • @questpondvideos
      @questpondvideos  4 года назад +1

      I get your point of synchronous call , i did one more example of moving to pure Async calls i still see do not see new threads.

    • @abissqlabissql6003
      @abissqlabissql6003 4 года назад

      @@questpondvideos Agreed i also do not see new threads when you run in full asyc as well. Regarding async using pool is right but not fully right . The pool thread is only for sync context which you explained in later part of video. Good going.

    • @questpondvideos
      @questpondvideos  4 года назад +1

      @@abissqlabissql6003 yes so right the extra thread what is created in asyn is for context sync not for actual execution.

  • @prashantlawhatre7007
    @prashantlawhatre7007 2 года назад

    Excellent video. One suggestion though, please be careful when using gender pronouns (I know that it was unintentional but still). Using neutral terms is a good practice. Thanks & regards

  • @jayan.mathew
    @jayan.mathew 2 года назад

    Insufficient example I think. When you run 2 async methods from main method without await what will happen?

    • @questpondvideos
      @questpondvideos  2 года назад

      Async needs await so this is technically not possible, If you are saying only from call side it will be a normal call.

    • @jayan.mathew
      @jayan.mathew 2 года назад

      May be you are talking about a very minimal (not a practical one) async scenario where Task is not involved.

    • @questpondvideos
      @questpondvideos  2 года назад

      ​@@jayan.mathew let me know what scenario you are discussing of Asyc with out Await

    • @jagdishdinkar2325
      @jagdishdinkar2325 2 года назад

      You can not run async with out await.???? You are confused

  • @alejandrobonilla3201
    @alejandrobonilla3201 2 года назад

    So you are saying async does not create more threads but we can clearly see a new thread created for the async method on your screen? Conclusion: either your explanation is wrong or my eyes are lying.

    • @questpondvideos
      @questpondvideos  2 года назад

      Then you did not hear me clearly. :-) The caller did not create the thread , the asynch process did. Sometimes the asynch process can be a CPU clock waiting so in those instances there are no threads. For synchng the context there is thread created which is not for the actual task.

  • @pawanagarnews1517
    @pawanagarnews1517 4 года назад

    Hi

  • @realKeiichiArt
    @realKeiichiArt 5 лет назад

    It is not threads, it is processes

  • @GumbieUsaGames
    @GumbieUsaGames 2 года назад

    Content is good but those analogy in examples are :(

  • @pramodkumarw
    @pramodkumarw 9 месяцев назад

    you confuse us sir,we need to learn more on this topic

  • @whonayem01
    @whonayem01 Год назад

    Thanks