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

  Рет қаралды 166,333

Questpond

Questpond

Күн бұрын

Пікірлер
@questpondvideos
@questpondvideos 3 жыл бұрын
Software Architecture Interview Questions : kzbin.info/www/bejne/d6W3mJaYgbSkg68 25+ OOPS Interview Questions : kzbin.info/www/bejne/q2qcqHSld893rLM 30 Important C# Interview Questions : kzbin.info/www/bejne/eHzcn3h4hdacf68 20+ SQL Server Interview Questions : kzbin.info/www/bejne/iXbHcnluorh-iZY 10+ Power BI Interview Questions : kzbin.info/www/bejne/eaDdlGyNg6eFqpY 20 MSBI Interview Questions : kzbin.info/www/bejne/hKjCpHt7gNOCi6c SQL Server Joins : kzbin.info/www/bejne/gYXZint7o9mppJo SQL Step by Step - kzbin.info/www/bejne/q3jPl4NvpJyeo7s Angular Step by Step Tutorial for Beginners : kzbin.info/www/bejne/Y2q5lIptgqd3qZo 25 Angular Interview Questions : kzbin.info/www/bejne/Y5vIoKx6f6mmia8 25 Important ASP.NET Interview Questions : kzbin.info/www/bejne/ponQfpejf7p2Zsk 35 Important JavaScript Interview Questions : kzbin.info/www/bejne/kJOXlYOfbKh0hLc 20 MySQL Interview Questions : kzbin.info/www/bejne/b5nJm3Zjd9WMaJI 5 MSBI Interview Questions : kzbin.info/www/bejne/a3abYmiXjaaqj7M 20 PHP Interview Questions : kzbin.info/www/bejne/Z5PTf4avo7qlopo
@polavarapuumasri5252
@polavarapuumasri5252 3 жыл бұрын
🔥
@ambikhpxxcvzcbnamali6441
@ambikhpxxcvzcbnamali6441 2 жыл бұрын
P
@MaheshSingh-ev8yh
@MaheshSingh-ev8yh Жыл бұрын
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.👏
@MicroftHunter
@MicroftHunter 5 жыл бұрын
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.
@lynndemarest1902
@lynndemarest1902 3 жыл бұрын
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?
@dustinzhang293
@dustinzhang293 4 жыл бұрын
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)
@questpondvideos
@questpondvideos 3 жыл бұрын
So right...
@shervilgupta92
@shervilgupta92 2 жыл бұрын
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?
@BigBhardwaj
@BigBhardwaj 6 жыл бұрын
A big shout out to you, Shiv ! and sincerely hope e-(ager) learners remain 'synchronized' for more 'context' and content on Multi-threading etc. !
@questpondvideos
@questpondvideos 4 жыл бұрын
Thanks. Do visit www.questpond.com
@UserSam832
@UserSam832 2 жыл бұрын
You should given Doctorate in C# Shiv. Ur knowledge and passion to help others is invaluable
@swarupfule3557
@swarupfule3557 3 жыл бұрын
Why there is just 835 likes. Definitely this is best style of teaching.
@ssssss1738
@ssssss1738 4 жыл бұрын
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!
@shaikhussain_ece
@shaikhussain_ece Жыл бұрын
I'm In Loop mode of your videos which are simple and clear
@vladimirkuznetsov3601
@vladimirkuznetsov3601 7 ай бұрын
Much better than some of Microsoft dev's talks on async/await!
@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.
@expertreviews1112
@expertreviews1112 6 жыл бұрын
Brilliant video. Can't appreciate enough
@questpondvideos
@questpondvideos 4 жыл бұрын
Thanks. Do visit www.questpond.com
@1989vinayak
@1989vinayak 3 жыл бұрын
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
@shayamsandhya
@shayamsandhya 5 жыл бұрын
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
@being_aslam_tiger
@being_aslam_tiger 2 жыл бұрын
Greatest Explained 👑💕
@minezgio3175
@minezgio3175 2 жыл бұрын
Really good video. Finally I was to able to understand this concept.
@mehdiichkarrane8808
@mehdiichkarrane8808 4 жыл бұрын
this is some very valuable content. thank you for the clear 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 Жыл бұрын
Sir After wathcing your video my threading conceopt and the async concept is clear.
@amoltiwari8371
@amoltiwari8371 Жыл бұрын
Thank you shiv sir to explain in depth
@ruler5408
@ruler5408 3 жыл бұрын
It's an awesome video and crystal clear on asynchronous working. Thank You
@31337flamer
@31337flamer 3 жыл бұрын
very informative .. made some things clear and showed some things that i was not aware of. thanks for sharing!
@amreshchandra4098
@amreshchandra4098 5 жыл бұрын
I never write comment on youtube.But for you i m writting.Very nice explaind.
@questpondvideos
@questpondvideos 4 жыл бұрын
Thanks. Do visit www.questpond.com
@dibbyo456
@dibbyo456 4 жыл бұрын
Everything is crystal clear now. Awesome video.
@questpondvideos
@questpondvideos 4 жыл бұрын
Thanks. Do visit www.questpond.com
@artak9439
@artak9439 2 ай бұрын
To avoid blocking the main thread, it must either perform context switching or create a new thread, there is no other option I think.
@chevn9260
@chevn9260 4 жыл бұрын
Thank you, I have learned to use async
@mohsinmemon3362
@mohsinmemon3362 2 жыл бұрын
great explanation . thanks for making this video.
@mirali829
@mirali829 Жыл бұрын
Thanks I 've got a deeper concept of it
@SzTz100
@SzTz100 2 жыл бұрын
Awesome explanation
@vrajeshbadgujar
@vrajeshbadgujar 8 ай бұрын
Great Explanation!
@simonsullivan8344
@simonsullivan8344 2 жыл бұрын
Brilliant made it clear
@Sopiro
@Sopiro 4 жыл бұрын
What a good explanation! I got to know a lot. thank you!
@questpondvideos
@questpondvideos 4 жыл бұрын
Thanks. Do visit www.questpond.com
@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
@sohaibalvi4410
@sohaibalvi4410 3 жыл бұрын
Worker Thread is a Synchronization "Thread that connected the callback and main thread" right sir?
@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.
@questpondvideos
@questpondvideos 4 жыл бұрын
Thanks. Do visit www.questpond.com
@konnelius
@konnelius 5 жыл бұрын
Thanks a lot for a very informative explanation :)
@questpondvideos
@questpondvideos 4 жыл бұрын
Thanks. Do visit www.questpond.com
@barteknikliborc7109
@barteknikliborc7109 2 жыл бұрын
greate explenation, thanks!
@nandanthareja
@nandanthareja 4 жыл бұрын
Commendable explanation
@TheSmoothPower
@TheSmoothPower 5 жыл бұрын
Excellent video, thank you Sir
@deepeng37
@deepeng37 2 жыл бұрын
Can you please explain .ConfigureAwait(false) of Async method ? Is it creating a background thread for asynch method?
@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.
@sony642
@sony642 6 жыл бұрын
Really worth to watch... appreciated!!
@questpondvideos
@questpondvideos 4 жыл бұрын
Thanks. Do visit www.questpond.com
@battuhant
@battuhant Жыл бұрын
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?
@unknownunknown-qx3gu
@unknownunknown-qx3gu 5 жыл бұрын
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.
@questpondvideos
@questpondvideos 4 жыл бұрын
Thanks. Do visit www.questpond.com
@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
@ktvideos1219
@ktvideos1219 5 жыл бұрын
Superb explanation!
@questpondvideos
@questpondvideos 4 жыл бұрын
Thanks. Do visit www.questpond.com
@jeetucobra
@jeetucobra 3 жыл бұрын
Sir can you help me when i using async then my Request.context is getting null
@victory4vivek1
@victory4vivek1 6 жыл бұрын
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.
@johnnguyen1655
@johnnguyen1655 4 жыл бұрын
brilliant tutorial!!!!!!!!!!!!!!!
@questpondvideos
@questpondvideos 4 жыл бұрын
Thanks. Do visit www.questpond.com
@stalera
@stalera 5 жыл бұрын
why don't you add the statemachine detail video url in the description. Or did I miss it?
@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 жыл бұрын
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 жыл бұрын
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.
@thesuperiorman8342
@thesuperiorman8342 5 жыл бұрын
I sub'd. Such a good explanation.
@questpondvideos
@questpondvideos 4 жыл бұрын
Thanks. Do visit www.questpond.com
@MukeshSharma-ru3ho
@MukeshSharma-ru3ho 4 жыл бұрын
well explained , thank you
@questpondvideos
@questpondvideos 4 жыл бұрын
Thanks. Do visit www.questpond.com
@mihailomarcetic2516
@mihailomarcetic2516 2 жыл бұрын
Gread video !!!!!
@pankajsingh-eg9hm
@pankajsingh-eg9hm 6 жыл бұрын
Excellent sir
@questpondvideos
@questpondvideos 4 жыл бұрын
Thanks. Do visit www.questpond.com
@gaoping7743
@gaoping7743 5 жыл бұрын
really good explain.
@questpondvideos
@questpondvideos 4 жыл бұрын
Thanks. Do visit www.questpond.com
@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.
@faeez4722
@faeez4722 4 жыл бұрын
Amazing
@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.
@vinodreddy1722
@vinodreddy1722 4 жыл бұрын
Where that async task runs,I case of threading task runs in thread t8?
@ziaasad2
@ziaasad2 6 жыл бұрын
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 жыл бұрын
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.
@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.
@InCircle
@InCircle 4 жыл бұрын
Hi Questond, the display of the video has incorrect spelling for async,
@questpondvideos
@questpondvideos 4 жыл бұрын
Well noted sir. Thanks and will correct the same.
@questpondvideos
@questpondvideos 4 жыл бұрын
Corrected Sir. Thanks
@mdora3983
@mdora3983 5 жыл бұрын
As far as i understand, when thread context changes then it is change the thread of first starting. am i right?
@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.
@mrityunjayahiremath3951
@mrityunjayahiremath3951 6 жыл бұрын
Please make a full course video on Power BI
@questpondvideos
@questpondvideos 4 жыл бұрын
Thanks and noted the same. Do visit www.questpond.com
@lamnguyen2106
@lamnguyen2106 4 жыл бұрын
thanks
@questpondvideos
@questpondvideos 4 жыл бұрын
Thanks. Do visit www.questpond.com
@HimalayaGarg
@HimalayaGarg 4 жыл бұрын
async free the main thread to continue next statements
@questpondvideos
@questpondvideos 4 жыл бұрын
With out creating new threads
@vamsikumar_n
@vamsikumar_n 5 жыл бұрын
super sir
@questpondvideos
@questpondvideos 4 жыл бұрын
Thanks. Do visit www.questpond.com
@jigarshah1438
@jigarshah1438 5 жыл бұрын
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 kzbin.info/www/bejne/gZfWaWeabM-Uipo Pls let me know if I have miss understood other video's explanation. Thanks.
@Kooshad1
@Kooshad1 3 жыл бұрын
link to part 1: kzbin.info/www/bejne/bnvIYopuZ9uqj68
@IvarDaigon
@IvarDaigon 5 жыл бұрын
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 жыл бұрын
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 жыл бұрын
@@abissqlabissql6003 yes so right the extra thread what is created in asyn is for context sync not for actual execution.
@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
@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
@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.
@realKeiichiArt
@realKeiichiArt 5 жыл бұрын
It is not threads, it is processes
@unknownunknown-qx3gu
@unknownunknown-qx3gu 5 жыл бұрын
That is not true pal, I'm sorry.
@GumbieUsaGames
@GumbieUsaGames 2 жыл бұрын
Content is good but those analogy in examples are :(
@pramodkumarw
@pramodkumarw 10 ай бұрын
you confuse us sir,we need to learn more on this topic
@pawanagarnews1517
@pawanagarnews1517 4 жыл бұрын
Hi
@whonayem01
@whonayem01 Жыл бұрын
Thanks
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
That's NOT How Async And Await Works in .NET!
12:25
Codewrinkles
Рет қаралды 29 М.
Top 20 Interview Questions - Web API - .NET C#
42:22
Interview Happy
Рет қаралды 244 М.
What are ASYNC and AWAIT in C#? Asynchronous Programming Tutorial
18:34
Await Async Tasks Are Getting Awesome in .NET 9!
9:24
Nick Chapsas
Рет қаралды 105 М.
What are Async and Await ( .NET 4.5 Interview question with answers)?
6:20
.NET Interview Preparation videos
Рет қаралды 268 М.
Multithreading vs Asynchronous Programming
11:00
Nutshell
Рет қаралды 17 М.
When You Shouldn't Use Await Async in .NET
7:51
Nick Chapsas
Рет қаралды 55 М.
C# Async Await Mistakes | Part 1
10:19
Amichai Mantinband
Рет қаралды 38 М.