If I do not want to do anything while waiting is there any point in using entity framework async methods?











up vote
0
down vote

favorite












if you have a controller that only contains this code:



var ThingQueryable = GetQueryable();

Thing ext = await ThingQueryable.FirstOrDefaultAsync();


Is there any benefit over this code?



Thing ext = ThingQueryable().FirstOrDefault();









share|improve this question






















  • Yes -- if ThingQueryable() performs I/O, or other things that would benefit from not having a thread synchronously waiting on the result. In fact, async/await is not primarily intended to allow you to do stuff while you're waiting, but to allow more stuff to happen in general.
    – Jeroen Mostert
    Nov 8 at 13:33















up vote
0
down vote

favorite












if you have a controller that only contains this code:



var ThingQueryable = GetQueryable();

Thing ext = await ThingQueryable.FirstOrDefaultAsync();


Is there any benefit over this code?



Thing ext = ThingQueryable().FirstOrDefault();









share|improve this question






















  • Yes -- if ThingQueryable() performs I/O, or other things that would benefit from not having a thread synchronously waiting on the result. In fact, async/await is not primarily intended to allow you to do stuff while you're waiting, but to allow more stuff to happen in general.
    – Jeroen Mostert
    Nov 8 at 13:33













up vote
0
down vote

favorite









up vote
0
down vote

favorite











if you have a controller that only contains this code:



var ThingQueryable = GetQueryable();

Thing ext = await ThingQueryable.FirstOrDefaultAsync();


Is there any benefit over this code?



Thing ext = ThingQueryable().FirstOrDefault();









share|improve this question













if you have a controller that only contains this code:



var ThingQueryable = GetQueryable();

Thing ext = await ThingQueryable.FirstOrDefaultAsync();


Is there any benefit over this code?



Thing ext = ThingQueryable().FirstOrDefault();






entity-framework






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 8 at 13:30









Craig

16013




16013












  • Yes -- if ThingQueryable() performs I/O, or other things that would benefit from not having a thread synchronously waiting on the result. In fact, async/await is not primarily intended to allow you to do stuff while you're waiting, but to allow more stuff to happen in general.
    – Jeroen Mostert
    Nov 8 at 13:33


















  • Yes -- if ThingQueryable() performs I/O, or other things that would benefit from not having a thread synchronously waiting on the result. In fact, async/await is not primarily intended to allow you to do stuff while you're waiting, but to allow more stuff to happen in general.
    – Jeroen Mostert
    Nov 8 at 13:33
















Yes -- if ThingQueryable() performs I/O, or other things that would benefit from not having a thread synchronously waiting on the result. In fact, async/await is not primarily intended to allow you to do stuff while you're waiting, but to allow more stuff to happen in general.
– Jeroen Mostert
Nov 8 at 13:33




Yes -- if ThingQueryable() performs I/O, or other things that would benefit from not having a thread synchronously waiting on the result. In fact, async/await is not primarily intended to allow you to do stuff while you're waiting, but to allow more stuff to happen in general.
– Jeroen Mostert
Nov 8 at 13:33












2 Answers
2






active

oldest

votes

















up vote
0
down vote














Is there any benefit over this code?




For client/server code in Windows Forms or in WPF the benefit is that you don't block the UI thread while waiting on the query. That's a big deal.



For Web apps or APIs the benefit is that you don't block a client thread while waiting on the results. For most database applications this benefit is tiny as you won't have many hundreds of concurrently-executing database requests, and so the benefit of not blocking threads is small.



There is also a slight risk that there won't be an available thread when the query is done, and so the method might take slightly longer to execute.






share|improve this answer




























    up vote
    0
    down vote













    It really depends what solution you are supposed to build.
    It the case is simple application that you know will be used by 5-10 users in intranet for a small company then using it you won't gain much benefit (such applications/system sounds pretty outdated for me). Even in this cause i will consider using async service only starting from the fact that it costs you the same time since it is really well supported by framework.



    The primary purpose is scalability from server side. So if you are building system that you want to scale you should go definitely for it. If you start using it, it won't magically improve your performance problems - if you have poor queries you still have to improve them.



    I like these two posts about showing performance benefit of using it:
    Scalable and Performant ASP.NET Core Web APIs and
    Async vs Blocking services.



    So in short, when start building system and things seems simple you will never know when they will get more complicated (they will probably go)- achieving better performance from step one of project life-cycle can save you lot of troubles later.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53208777%2fif-i-do-not-want-to-do-anything-while-waiting-is-there-any-point-in-using-entity%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote














      Is there any benefit over this code?




      For client/server code in Windows Forms or in WPF the benefit is that you don't block the UI thread while waiting on the query. That's a big deal.



      For Web apps or APIs the benefit is that you don't block a client thread while waiting on the results. For most database applications this benefit is tiny as you won't have many hundreds of concurrently-executing database requests, and so the benefit of not blocking threads is small.



      There is also a slight risk that there won't be an available thread when the query is done, and so the method might take slightly longer to execute.






      share|improve this answer

























        up vote
        0
        down vote














        Is there any benefit over this code?




        For client/server code in Windows Forms or in WPF the benefit is that you don't block the UI thread while waiting on the query. That's a big deal.



        For Web apps or APIs the benefit is that you don't block a client thread while waiting on the results. For most database applications this benefit is tiny as you won't have many hundreds of concurrently-executing database requests, and so the benefit of not blocking threads is small.



        There is also a slight risk that there won't be an available thread when the query is done, and so the method might take slightly longer to execute.






        share|improve this answer























          up vote
          0
          down vote










          up vote
          0
          down vote










          Is there any benefit over this code?




          For client/server code in Windows Forms or in WPF the benefit is that you don't block the UI thread while waiting on the query. That's a big deal.



          For Web apps or APIs the benefit is that you don't block a client thread while waiting on the results. For most database applications this benefit is tiny as you won't have many hundreds of concurrently-executing database requests, and so the benefit of not blocking threads is small.



          There is also a slight risk that there won't be an available thread when the query is done, and so the method might take slightly longer to execute.






          share|improve this answer













          Is there any benefit over this code?




          For client/server code in Windows Forms or in WPF the benefit is that you don't block the UI thread while waiting on the query. That's a big deal.



          For Web apps or APIs the benefit is that you don't block a client thread while waiting on the results. For most database applications this benefit is tiny as you won't have many hundreds of concurrently-executing database requests, and so the benefit of not blocking threads is small.



          There is also a slight risk that there won't be an available thread when the query is done, and so the method might take slightly longer to execute.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 8 at 15:29









          David Browne - Microsoft

          13k1524




          13k1524
























              up vote
              0
              down vote













              It really depends what solution you are supposed to build.
              It the case is simple application that you know will be used by 5-10 users in intranet for a small company then using it you won't gain much benefit (such applications/system sounds pretty outdated for me). Even in this cause i will consider using async service only starting from the fact that it costs you the same time since it is really well supported by framework.



              The primary purpose is scalability from server side. So if you are building system that you want to scale you should go definitely for it. If you start using it, it won't magically improve your performance problems - if you have poor queries you still have to improve them.



              I like these two posts about showing performance benefit of using it:
              Scalable and Performant ASP.NET Core Web APIs and
              Async vs Blocking services.



              So in short, when start building system and things seems simple you will never know when they will get more complicated (they will probably go)- achieving better performance from step one of project life-cycle can save you lot of troubles later.






              share|improve this answer



























                up vote
                0
                down vote













                It really depends what solution you are supposed to build.
                It the case is simple application that you know will be used by 5-10 users in intranet for a small company then using it you won't gain much benefit (such applications/system sounds pretty outdated for me). Even in this cause i will consider using async service only starting from the fact that it costs you the same time since it is really well supported by framework.



                The primary purpose is scalability from server side. So if you are building system that you want to scale you should go definitely for it. If you start using it, it won't magically improve your performance problems - if you have poor queries you still have to improve them.



                I like these two posts about showing performance benefit of using it:
                Scalable and Performant ASP.NET Core Web APIs and
                Async vs Blocking services.



                So in short, when start building system and things seems simple you will never know when they will get more complicated (they will probably go)- achieving better performance from step one of project life-cycle can save you lot of troubles later.






                share|improve this answer

























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  It really depends what solution you are supposed to build.
                  It the case is simple application that you know will be used by 5-10 users in intranet for a small company then using it you won't gain much benefit (such applications/system sounds pretty outdated for me). Even in this cause i will consider using async service only starting from the fact that it costs you the same time since it is really well supported by framework.



                  The primary purpose is scalability from server side. So if you are building system that you want to scale you should go definitely for it. If you start using it, it won't magically improve your performance problems - if you have poor queries you still have to improve them.



                  I like these two posts about showing performance benefit of using it:
                  Scalable and Performant ASP.NET Core Web APIs and
                  Async vs Blocking services.



                  So in short, when start building system and things seems simple you will never know when they will get more complicated (they will probably go)- achieving better performance from step one of project life-cycle can save you lot of troubles later.






                  share|improve this answer














                  It really depends what solution you are supposed to build.
                  It the case is simple application that you know will be used by 5-10 users in intranet for a small company then using it you won't gain much benefit (such applications/system sounds pretty outdated for me). Even in this cause i will consider using async service only starting from the fact that it costs you the same time since it is really well supported by framework.



                  The primary purpose is scalability from server side. So if you are building system that you want to scale you should go definitely for it. If you start using it, it won't magically improve your performance problems - if you have poor queries you still have to improve them.



                  I like these two posts about showing performance benefit of using it:
                  Scalable and Performant ASP.NET Core Web APIs and
                  Async vs Blocking services.



                  So in short, when start building system and things seems simple you will never know when they will get more complicated (they will probably go)- achieving better performance from step one of project life-cycle can save you lot of troubles later.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 9 at 8:22

























                  answered Nov 8 at 15:31









                  charino

                  30135




                  30135






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53208777%2fif-i-do-not-want-to-do-anything-while-waiting-is-there-any-point-in-using-entity%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Schultheiß

                      Liste der Kulturdenkmale in Wilsdruff

                      Android Play Services Check