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

Sdílet
Vložit
  • čas přidán 26. 06. 2024
  • For more such videos visit www.questpond.com
    For more such videos subscribe / questpondvideos
    See our other Step by Step video series below :-
    JavaScript Interview Questions: • JavaScript Interview Q...
    C# tutorial for beginners(4 hrs):- • C# Tutorial for Beginn...
    ASP.NET MVC Core Interview Questions with answers:- • ASP.NET MVC Interview ...
    C# interview questions and answers:- • C# Interview Questions...
    Abstract class vs Interface in C# :- • Abstract Class vs Inte...
    Learn Azure Step by Step:- • Azure Tutorial for Beg...
    Azure AZ-900 fundamentals certification :- • AZ 900 Certification |...
    Angular Interview Questions and Answers :- • Angular Interview Ques...
    Learn Angular tutorial step by step tinyurl.com/ycd9j895
    Learn MVC 5 step by step in 16 hours:- • Learn ASP.NET MVC 5 ( ...
    Learn Design Pattern Step by Step goo.gl/eJdn0m
    Learn MSBI Step by Step in 32 hours:- goo.gl/TTpFZN
    Learn SQL Server Step by Step tinyurl.com/ja4zmwu
    Python Tutorial for Beginners:- • Python Tutorial for Be...
    Learn Data Science in 1 hour :- tinyurl.com/y5o7qbau
    Learn Power BI Step by Step:- tinyurl.com/y6thhkxw
    PHP Interview Questions : • PHP Interview Question...
    Learn Tableau step by step :- tinyurl.com/kh6ojyo
    -----------------------------------------------------------------------------------------------
    For more details :-
    🌐 Website : www.questpond.com
    📱 Mob. No. : +91-9967590707 / +91 7700975156 / +91-22-49786776
    📧Email : questpond@questpond.com / questpond@gmail.com / questpond@yahoo.com
    Share, Support, Subscribe and Connect us on!!!
    CZcams: / questpondvideos
    Twitter: / questpond
    Instagram : / questpond
    Facebook : / questpond
    #AsyncvsThreadsC# #Async&ThreadsinCsharp #C#InterviewQuestionsandAnswers #C#Interviewquestions #DefferenceBetweenAsync&Threads #CSharpInterviewQuestions

Komentáře • 134

  • @questpondvideos
    @questpondvideos  Před 3 lety +4

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

  • @MicroftHunter
    @MicroftHunter Před 5 lety +2

    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 Před 3 lety +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)

  • @vladimirkuznetsov3601
    @vladimirkuznetsov3601 Před 15 dny

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

  • @TheSmoothPower
    @TheSmoothPower Před 4 lety

    Excellent video, thank you Sir

  • @mehdiichkarrane8808
    @mehdiichkarrane8808 Před 3 lety +1

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

  • @ssssss1738
    @ssssss1738 Před 3 lety +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!

  • @lynndemarest1902
    @lynndemarest1902 Před 2 lety +13

    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?

  • @ruler5408
    @ruler5408 Před 2 lety

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

  • @chevn9260
    @chevn9260 Před 3 lety +1

    Thank you, I have learned to use async

  • @expertreviews1112
    @expertreviews1112 Před 5 lety +7

    Brilliant video. Can't appreciate enough

  • @minezgio3175
    @minezgio3175 Před 2 lety

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

  • @MaheshSingh-ev8yh
    @MaheshSingh-ev8yh Před 9 měsíci +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.👏

  • @wpelfeta
    @wpelfeta Před rokem

    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.

  • @31337flamer
    @31337flamer Před 3 lety

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

  • @amoltiwari8371
    @amoltiwari8371 Před rokem

    Thank you shiv sir to explain in depth

  • @mohsinmemon3362
    @mohsinmemon3362 Před rokem

    great explanation . thanks for making this video.

  • @nandanthareja
    @nandanthareja Před 3 lety

    Commendable explanation

  • @BigBhardwaj
    @BigBhardwaj Před 5 lety +3

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

  • @being_aslam_tiger
    @being_aslam_tiger Před rokem

    Greatest Explained 👑💕

  • @vrajeshbadgujar
    @vrajeshbadgujar Před měsícem

    Great Explanation!

  • @shaikhussain_ece
    @shaikhussain_ece Před rokem

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

  • @SzTz100
    @SzTz100 Před rokem

    Awesome explanation

  • @simonsullivan8344
    @simonsullivan8344 Před rokem

    Brilliant made it clear

  • @sony642
    @sony642 Před 5 lety

    Really worth to watch... appreciated!!

  • @dibbyo456
    @dibbyo456 Před 4 lety

    Everything is crystal clear now. Awesome video.

  • @mirali829
    @mirali829 Před 11 měsíci

    Thanks I 've got a deeper concept of it

  • @barteknikliborc7109
    @barteknikliborc7109 Před 2 lety

    greate explenation, thanks!

  • @UserSam832
    @UserSam832 Před rokem

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

  • @Sopiro
    @Sopiro Před 4 lety +1

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

  • @konnelius
    @konnelius Před 4 lety +1

    Thanks a lot for a very informative explanation :)

  • @swarupfule3557
    @swarupfule3557 Před 3 lety +2

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

  • @impostersyndromedev
    @impostersyndromedev Před 4 lety

    Excellent video! Love your code samples.

  • @shubhamchoudhary5957
    @shubhamchoudhary5957 Před 5 měsíci

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

  • @faeez4722
    @faeez4722 Před 3 lety

    Amazing

  • @rukmininaik987
    @rukmininaik987 Před 4 lety

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

  • @shervilgupta92
    @shervilgupta92 Před rokem +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 Před rokem

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

    • @shervilgupta92
      @shervilgupta92 Před rokem

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

    • @frankabignale2176
      @frankabignale2176 Před rokem

      @@shervilgupta92 what do you work on?

  • @1989vinayak
    @1989vinayak Před 2 lety +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

  • @whonayem01
    @whonayem01 Před rokem

    Thanks

  • @ktvideos1219
    @ktvideos1219 Před 4 lety

    Superb explanation!

  • @shyamladalomaharo
    @shyamladalomaharo Před 5 lety +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

  • @thesuperiorman8342
    @thesuperiorman8342 Před 5 lety +1

    I sub'd. Such a good explanation.

  • @MukeshSharma-ru3ho
    @MukeshSharma-ru3ho Před 4 lety

    well explained , thank you

  • @xybersurfer
    @xybersurfer Před 2 lety

    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

  • @pankajsingh-eg9hm
    @pankajsingh-eg9hm Před 5 lety

    Excellent sir

  • @mihailomarcetic2516
    @mihailomarcetic2516 Před 2 lety

    Gread video !!!!!

  • @gaoping7743
    @gaoping7743 Před 5 lety

    really good explain.

  • @johnnguyen1655
    @johnnguyen1655 Před 4 lety

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

  • @amreshchandra4098
    @amreshchandra4098 Před 4 lety

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

  • @stalera
    @stalera Před 4 lety

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

  • @deepeng37
    @deepeng37 Před 2 lety

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

  • @unknownunknown-qx3gu
    @unknownunknown-qx3gu Před 4 lety +7

    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  Před 3 lety

      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.

  • @mdora3983
    @mdora3983 Před 5 lety

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

  • @battuhant
    @battuhant Před 5 měsíci

    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?

  • @vamsikumar_n
    @vamsikumar_n Před 4 lety

    super sir

  • @sohaibalvi4410
    @sohaibalvi4410 Před 3 lety +1

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

  • @lamnguyen2106
    @lamnguyen2106 Před 4 lety

    thanks

  • @victory4vivek1
    @victory4vivek1 Před 5 lety +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  Před 5 lety

      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.

  • @jeetucobra
    @jeetucobra Před 2 lety

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

  • @ritikamanchanda9723
    @ritikamanchanda9723 Před 4 lety

    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 Před 4 lety +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 Před 3 lety

      Thanks @@AmitChoudhary10 for clearing my doubt.

    • @lynndemarest1902
      @lynndemarest1902 Před 2 lety +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.

  • @vinodreddy1722
    @vinodreddy1722 Před 3 lety

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

  • @mrityunjayahiremath3951

    Please make a full course video on Power BI

    • @questpondvideos
      @questpondvideos  Před 4 lety

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

  • @psych4054
    @psych4054 Před 3 lety

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

  • @calaiarasan7318
    @calaiarasan7318 Před 4 lety

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

    • @ziv4545
      @ziv4545 Před 4 lety

      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.

  • @ziaasad2
    @ziaasad2 Před 5 lety

    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 Před 5 lety +1

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

    • @questpondvideos
      @questpondvideos  Před 4 lety

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

  • @wonseoklee80
    @wonseoklee80 Před rokem

    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  Před rokem

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

    • @wonseoklee80
      @wonseoklee80 Před rokem

      @@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.

  • @Kooshad1
    @Kooshad1 Před 2 lety

    link to part 1: czcams.com/video/8Je1W82vwYM/video.html

  • @jigarshah1438
    @jigarshah1438 Před 4 lety +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 czcams.com/video/Kfs84d7jaT8/video.html
    Pls let me know if I have miss understood other video's explanation.
    Thanks.

  • @abid777ful
    @abid777ful Před 5 lety

    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  Před 5 lety

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

    • @abid777ful
      @abid777ful Před 5 lety

      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.

  • @HimalayaGarg
    @HimalayaGarg Před 3 lety

    async free the main thread to continue next statements

  • @InCircle
    @InCircle Před 4 lety

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

  • @pawanagarnews1517
    @pawanagarnews1517 Před 3 lety

    Hi

  • @lazycyclone
    @lazycyclone Před rokem

    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  Před rokem

      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.

  • @Wynell
    @Wynell Před 2 lety

    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  Před 2 lety

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

    • @user-nk9ez6ly5s
      @user-nk9ez6ly5s Před 2 lety

      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  Před 2 lety

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

  • @realKeiichiArt
    @realKeiichiArt Před 5 lety

    It is not threads, it is processes

  • @alejandrobonilla3201
    @alejandrobonilla3201 Před 2 lety

    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  Před 2 lety

      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.

  • @jayan.mathew
    @jayan.mathew Před rokem

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

    • @questpondvideos
      @questpondvideos  Před rokem

      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 Před rokem

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

    • @questpondvideos
      @questpondvideos  Před rokem

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

    • @jagdishdinkar2325
      @jagdishdinkar2325 Před rokem

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

  • @prashantlawhatre7007
    @prashantlawhatre7007 Před 2 lety

    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

  • @GumbieUsaGames
    @GumbieUsaGames Před 2 lety

    Content is good but those analogy in examples are :(

  • @IvarDaigon
    @IvarDaigon Před 4 lety +16

    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  Před 3 lety +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 Před 3 lety

      @@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  Před 3 lety +1

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

  • @pramodkumarw
    @pramodkumarw Před 3 měsíci

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