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();
entity-framework
add a comment |
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();
entity-framework
Yes -- ifThingQueryable()
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
add a comment |
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();
entity-framework
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
entity-framework
asked Nov 8 at 13:30
Craig
16013
16013
Yes -- ifThingQueryable()
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
add a comment |
Yes -- ifThingQueryable()
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 8 at 15:29
David Browne - Microsoft
13k1524
13k1524
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Nov 9 at 8:22
answered Nov 8 at 15:31
charino
30135
30135
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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