What are Async and Await ( .NET 4.5 Interview question with answers)?

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024
  • For more such videos visit www.questpond.com
    For more such videos subscribe www.youtube.co...
    See our other Step by Step video series below :-
    Learn C# Step by Step goo.gl/FNlqn3
    Learn Design Pattern Step by Step:- goo.gl/eJdn0m
    Learn Angular tutorial step by step tinyurl.com/yc...
    Learn MVC Core step by step :- tinyurl.com/y9j...
    Learn Azure Step by Step :- tinyurl.com/y6...
    Learn SharePoint Step by Step in 8 hours:- goo.gl/XQKHeP
    Python Tutorial for Beginners:- • Python Tutorial for Be...
    Learn Data Science in 1 hour :- tinyurl.com/y5...
    Learn Power BI Step by Step:- tinyurl.com/y6...
    Learn MSBI Step by Step in 32 hours:- goo.gl/TTpFZN
    Learn SQL Server Step by Step tinyurl.com/ja4...
    Learn Tableau step by step :- tinyurl.com/kh...
    Async and await are markers which mark code positions from where control should resume after a task (thread) completes.
    We are also distributing a 200 page Ebook ".NET Interview Question and Answers". If you want this ebook please share this video in your facebook/twitter/linkedin account and email us on
    questpond@questpond.com with the shared link and we will email you the PDF.

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

  • @dnfvideo
    @dnfvideo  3 ปีที่แล้ว

    Do not miss our Interview Question video series
    25 Important ASP.NET Interview Questions : th-cam.com/video/pXmMdmJUC0g/w-d-xo.html
    30 Important C# Interview Questions : th-cam.com/video/BKynEBPqiIM/w-d-xo.html
    25 Angular Interview Questions : th-cam.com/video/-jeoyDJDsSM/w-d-xo.html
    5 MSBI Interview Questions : th-cam.com/video/5E815aXAwYQ/w-d-xo.html

  • @gastos7771
    @gastos7771 9 ปีที่แล้ว +2

    Well explained, thank you very much. This is unlike some other videos where speakers are very slow to explain, don't explain the meat of the matter, and leaves the watcher confused.
    I Initially thought I could use Async and Await in a method that is not running on thread or task, and my application was hanging, but this video of yours explained it beautifully.
    I'll be subscribing on your videos and watch the other ones, really grateful.

  • @shanpalaniram
    @shanpalaniram 6 ปีที่แล้ว +17

    Asynchronous programming is used to prevent blocking UI for long execution tasks or I/O operations hence it keeps the UI responsive to the user. The same thing can be achieved by using thread also, but have to write a bit complicated coding. The async just simplifies it for easy writing and reading.

  • @ranikala2395
    @ranikala2395 8 ปีที่แล้ว +9

    very clear with easy simple English.so that I can understand very easy.thanks a lot. Excellent pa.continue .continue

  • @stannisbarracuda5693
    @stannisbarracuda5693 6 ปีที่แล้ว

    your explanations are pure gold

  • @praveenshukla4623
    @praveenshukla4623 9 ปีที่แล้ว +6

    very nice explanation but my question is instead of using the await keyword can we use synchronous programming. because await also blocks the control and resume when subtask is completed .

    • @MrKsackel12345
      @MrKsackel12345 7 ปีที่แล้ว +3

      yes right. at 3.08. instead of using tpl to invoke the long task. one could have just made a synchronous call to long task.
      did you get an answer to this ?

  • @being_aslam_tiger
    @being_aslam_tiger ปีที่แล้ว

    Well explained, thank you very much.

  • @EgiRoka
    @EgiRoka 7 ปีที่แล้ว

    this is to avoid breaking processes of uncertain duration... like sending an amail programatically via smtp...etc...

  • @Bobby-mf6fw
    @Bobby-mf6fw 2 ปีที่แล้ว

    Wow ,so clearly explained. 👍

  • @udayakumarp3875
    @udayakumarp3875 3 ปีที่แล้ว

    Great short and sweet

  • @shyamkalaskar8974
    @shyamkalaskar8974 4 ปีที่แล้ว

    Thank you sir, very well explain.

  • @naineshsuthar
    @naineshsuthar 5 ปีที่แล้ว

    very clear and nice ezey

  • @factworld4375
    @factworld4375 5 ปีที่แล้ว

    It's really useful thanks.

  • @sumitshinde5653
    @sumitshinde5653 4 ปีที่แล้ว

    What if LongTask has parameters i.e. public static void LongTask( string a , string b){ // do something with a ,b }

  • @siddharthpachori9302
    @siddharthpachori9302 8 ปีที่แล้ว

    Good Explanation

  • @nukec
    @nukec 10 ปีที่แล้ว

    good explanation.

  • @mikeyf504
    @mikeyf504 8 ปีที่แล้ว

    thank you !

  • @yiyuan6844
    @yiyuan6844 7 ปีที่แล้ว

    good

  • @MohanrajPeriasamy
    @MohanrajPeriasamy 10 ปีที่แล้ว

    where to use this? can you please explain...real time usage...

    • @RJBikerRajeev
      @RJBikerRajeev 9 ปีที่แล้ว +1

      Mohanraj Periasamy suppose you are creating a application where a large CSV files data save into DB, so it's take lots of time to validate data and save. so you can use this.

    • @FirstLast-ws7zw
      @FirstLast-ws7zw 8 ปีที่แล้ว

      Wherever you would use TPL or threading. It clears up the code.

  • @ivandrofly
    @ivandrofly 11 ปีที่แล้ว

    Thank you so much :)

  • @manchusandy1
    @manchusandy1 2 ปีที่แล้ว +3

    Hey Shiv, in this case sequential programming serves the purpose. Why should we go for Task and make it wait until completed ?

    • @nilgiripaiya
      @nilgiripaiya ปีที่แล้ว

      very true...scrolled down if anyone had asked the same, yes u have asked im waiting for the reply too

  • @samanthkolisetty9782
    @samanthkolisetty9782 4 ปีที่แล้ว +2

    this can be achieved without these keywords by calling method directly right

  • @shivamsom4648
    @shivamsom4648 6 ปีที่แล้ว +3

    I have a question
    Why not just call the LongTask methods as it is,
    public void Method()
    {
    LongTask() ; //No parallel processing
    Console.WriteLine(""Do something");
    }
    public static void LongTask()
    {
    Thread.sleep(20000);
    }
    If i can make it wait like this, then why should I go for the async and await?

    • @NeerajKumar-zh9bv
      @NeerajKumar-zh9bv 3 ปีที่แล้ว

      It will use only main Thread. It is not good approach to wait the main Thread.

  • @ruwanc2003
    @ruwanc2003 ปีที่แล้ว

    when i used in webapplication it is not working, why is that ?

  • @InCircle
    @InCircle 2 ปีที่แล้ว

    Spelling of async is incorrect at 0:12. Great content.

  • @avismnayush
    @avismnayush 7 ปีที่แล้ว +2

    You skipped over the main usage of async/await which is to achieve responsiveness for UI or scalability for Web (and NOT asynchrony). The threads yields control back to caller when it encounters await.

    • @jayantdarade
      @jayantdarade 3 ปีที่แล้ว +1

      correctly pointed out...watch kudvenkat sir's video

  • @akiren7730
    @akiren7730 5 ปีที่แล้ว +1

    Tasks can be executed with lambda like Await Task.Run(() => LongTask());
    Shorter than New Action

  • @dswoopy
    @dswoopy 11 ปีที่แล้ว +2

    Contd from earlier comment.... Use of Async and Await keywords helps the programmer to get rid of writing spaghetti code (interlinked code) with callbacks making it simple.

  • @TheNextG7me
    @TheNextG7me 5 ปีที่แล้ว +2

    Short, clear and straighforward. Thank you Sir.

  • @harishmani316
    @harishmani316 ปีที่แล้ว

    How many await can be used

  • @kamranbigdely
    @kamranbigdely 10 ปีที่แล้ว +1

    Pronunciation of "async" is /eɪˈsɪŋk/
    p.s. Good code example :)

  • @dswoopy
    @dswoopy 11 ปีที่แล้ว +3

    Good video. It is worth mentioning that Async and Await keywords are used in asynchronous programming. Earlier the programmers were required to write a callback method for each async function and then if they wanted some block of code to be executed after the aync operation is over, that block of code was required to be written in the callback method. Writing callback method for each async function could become very clumsy and hard to read and understand...contd.

    • @anugrahkm7255
      @anugrahkm7255 ปีที่แล้ว

      hi, what to do if i want "main thread" to be executed after the new thread?

  • @NileshGaikwad99
    @NileshGaikwad99 2 ปีที่แล้ว

    Thanks for good information I use await and async but now i clear about that

  • @eijikisaragi6958
    @eijikisaragi6958 7 ปีที่แล้ว +1

    What an explanation, simple to understand and apply, thanks. thumbs up

  • @nileshkumarnarware1397
    @nileshkumarnarware1397 3 ปีที่แล้ว

    Very Good Explained Sir... easily understand anyone., Thank You So much for describing in details Sir,,

  • @rreennommaann
    @rreennommaann 3 ปีที่แล้ว

    Excellent description, now I understand. Everything else I looked at, I could not understand. Thank You.

  • @shwetanadar1081
    @shwetanadar1081 2 ปีที่แล้ว

    Venkat's teaching is the same as Virat Kholi hitting a six even in difficult situations

  • @tarunkumargubba
    @tarunkumargubba 7 ปีที่แล้ว

    we should not release the main thread until all sub-threads are completed otherwise there is no way to catch exceptions if any occurs in sub-threads

  • @arvindchourasiya4738
    @arvindchourasiya4738 5 ปีที่แล้ว

    Nice video.
    But you are missing something significant here about async & await..

  • @aniketjadhav9638
    @aniketjadhav9638 4 ปีที่แล้ว

    No one can explain .Net better than Shiv sir❤. Thanks for the video sir.

  • @maheshvanamala7521
    @maheshvanamala7521 3 ปีที่แล้ว

    Really super explanation sir.within less words ..🙏

  • @randhirraj9192
    @randhirraj9192 4 ปีที่แล้ว

    Very good explanation..thanks

  • @balthierspark382
    @balthierspark382 9 ปีที่แล้ว

    can you give us a download link for this program ..
    thank you

  • @scarbus
    @scarbus 7 ปีที่แล้ว

    I got epiphany when you said "The main thread did not wait, guys".

  • @carlosarias8556
    @carlosarias8556 5 ปีที่แล้ว

    Excelent! but why always console mode ...

  • @VEGETADTX
    @VEGETADTX 8 ปีที่แล้ว +3

    What I don't understand is - aren't things already like that in C# even without async and await keywords??? I mean, doesn't code go step by step anyway?
    Is it because the Task.Run() itself is ignoring the order of execution?

    • @manisharyal4239
      @manisharyal4239 7 ปีที่แล้ว +2

      Without using any of these jargons in a simple program we can execute one statement after another, right? That happens in a single thread or the main thread.
      What Task.Run() does is it does the work in a different thread (actually, it is from a thread pool and they are slightly different, but nvm let's consider thread). So the main program is running on one thread and the Task.Run() runs on a different thread. It runs simultaneously.
      And to make it run step by step way using many threads, we use async and await. Hope this helps :)

    • @VEGETADTX
      @VEGETADTX 7 ปีที่แล้ว +1

      Perfectly clear! That's what I call an explanation ;)
      Thank you very much! :)

    • @frozenprakash
      @frozenprakash 7 ปีที่แล้ว +1

      simple words,
      while the pointer is in await Task.Run...
      The UI (Form) will be perfectly active, you can move, click do everything,
      but in normal program running line by line, your UI is frozen completely during that 20,000 ms [20 seconds],
      NOW THATS THE CATCH :)

  • @nitishmyluck
    @nitishmyluck 7 ปีที่แล้ว

    Love u sir ji.. very simplified each n every tough topics..Awesome way to explain..

  • @knseeker1524
    @knseeker1524 4 ปีที่แล้ว

    superb explanation!!! thanks sir, keep it up

  • @taruntarun05
    @taruntarun05 4 ปีที่แล้ว

    Code not workinh Now?

  • @manjeetnandal1
    @manjeetnandal1 5 ปีที่แล้ว

    Nice explained!
    Great thanks!

  • @flaviusioan69
    @flaviusioan69 5 ปีที่แล้ว

    Clear and simple explanation...tnx

  • @thedude3544
    @thedude3544 5 ปีที่แล้ว

    Thanks a lot for this information

  • @ga7853
    @ga7853 5 ปีที่แล้ว

    Thank you so much, that was very helpful. God bless.

  • @MrKsackel12345
    @MrKsackel12345 7 ปีที่แล้ว

    yes very good explanation. very clear.

  • @БориславБорисов-я2ы
    @БориславБорисов-я2ы 4 ปีที่แล้ว

    ClearlyI

  • @betechnicaltech
    @betechnicaltech 5 ปีที่แล้ว

    Excellent

  • @anjipurum3769
    @anjipurum3769 4 ปีที่แล้ว

    Good Video, Thank you

  • @pratikranchhod889
    @pratikranchhod889 6 ปีที่แล้ว

    Hi thanks for the video...but what is the difference between await vs wait()..

    • @ishansrivastava7215
      @ishansrivastava7215 6 ปีที่แล้ว +1

      In this example, Wait() should have been used.
      Task.Run returns a Task which is an 'awaitable', hence we can 'await' it, but we can wait simply by calling Task.Wait() method. Typically, async/await should be used for naturally asynchronous operations/methods - HTTP calls, for example.
      Thanks.

  • @cristianarteaga
    @cristianarteaga 8 ปีที่แล้ว

    Brief and complete explanation. Thank you!

  • @ashish2038
    @ashish2038 6 ปีที่แล้ว

    What if the longTask method is made async will it wait at your debugger ?

  • @ManishKumar-wn2gn
    @ManishKumar-wn2gn 6 ปีที่แล้ว

    Excellent explaination

  • @phyothu3695
    @phyothu3695 5 ปีที่แล้ว

    Thank you

  • @vinaypugalia6090
    @vinaypugalia6090 9 ปีที่แล้ว +14

    Good Video..thanks!
    However, I believe there should be a correction in the statement made @ around 3:57 mins where the author says that aync & await should be used in pairs.
    AFAIK if any method uses "await", it is mandatory to mark that method as "async" but the vice versa is not true. A method could be marked as "async" with having any "await" keyword inside it. In this case, it will be treated as a synchronous method.
    Secondly, as per the naming convention standards, an async method methodname should always me suffixed by "async" word; e.g. PrintAsync()
    Hope, this helps to the viewers.
    Thanks!

    • @binson143
      @binson143 9 ปีที่แล้ว +1

      Vinay Pugalia yes u r correct

    • @praveenshukla4623
      @praveenshukla4623 9 ปีที่แล้ว +2

      binson eldhose my question is instead of using the await keyword can we use synchronous programming. because await also blocks the control and resume when subtask is completed .

    • @buttofthejoke
      @buttofthejoke 9 ปีที่แล้ว +5

      Praveen Shukla I think that is incorrect. As mentioned in the end of the video, the thread from the Main method executed (ie. ran asynchronously), the only thing that waits is the line of code after await WITHIN the Async method.. ie.
      OUTPUT ->
      Main Thread
      New Thread
      In Synchronous, the entire thread would await..
      OUTPUT ->
      New Thread
      Main Thread
      Synchronous blocks entire thread,
      Task blocks nothing,
      Async blocks (rather forces to wait) only content within the ASYNC method.

    • @nkjain01
      @nkjain01 8 ปีที่แล้ว

      +Praveen Shukla - Hi Its not possible

  • @abhijitv
    @abhijitv 6 ปีที่แล้ว

    Brilliant Video !

  • @galaxyhardwares6036
    @galaxyhardwares6036 6 ปีที่แล้ว

    Excellent