Click here to Skip to main content
14,843,944 members
Home / Discussions / C#
   

C#

 
GeneralRe: Write Async Method Pin
Gerry Schmitz28-Jan-21 14:57
mveGerry Schmitz28-Jan-21 14:57 
AnswerRe: Write Async Method Pin
Richard Deeming27-Jan-21 21:46
mveRichard Deeming27-Jan-21 21:46 
GeneralRe: Write Async Method Pin
Kevin Marois28-Jan-21 6:27
professionalKevin Marois28-Jan-21 6:27 
GeneralRe: Write Async Method Pin
Kevin Marois28-Jan-21 7:53
professionalKevin Marois28-Jan-21 7:53 
GeneralRe: Write Async Method Pin
Richard Deeming28-Jan-21 22:10
mveRichard Deeming28-Jan-21 22:10 
GeneralRe: Write Async Method Pin
Kevin Marois29-Jan-21 9:12
professionalKevin Marois29-Jan-21 9:12 
GeneralRe: Write Async Method Pin
Richard Deeming31-Jan-21 22:05
mveRichard Deeming31-Jan-21 22:05 
GeneralRe: Write Async Method Pin
Kevin Marois31-Jan-21 22:36
professionalKevin Marois31-Jan-21 22:36 
Thanks.

What I'm after here is to make my WPF app responsive during Web API calls. You provided some asynv/await examples, but what the don't show is.. what is it that makes
command.ExecuteScalarAsync()
asynchronous? Isn't ExecuteScalarAsync just returning a task? This is my real question... What is it on the server that allows the client to await it?

I'm using Linq-To-Sql on my server. Right now, my DAL code is pretty straightforward:
public CompanyEntity GetCompanyById(int companyId)
{
    using (var dc = GetDataContext())
    {
        var cust = (from c in dc.Companies
                    where c.Id == companyId
                    select new CompanyEntity
                    {
                        Id = c.Id,
                        CompanyName = c.CompanyName
                    }).FirstOrDefault();

        return cust;
    }
}
Then, in my WPF ViewModel I do
public override void Load(int id)
{
    Customer = AppCore.BizObject.GetCustomerById(id);
}
But to make it truly async, I would need
public override async void Load(int id)
{
    await Task.Factory.StartNew(() =>
    {
        var customer = AppCore.BizObject.GetCustomerByIdAsync(id);
    });
}
I'm using a task to keep the UI responsive. But what should the server side method look like? Something close to this??
public Task<CompanyEntity> GetCompanyByIdAsync(int companyId)
{
    using (var dc = GetDataContext())
    {
        var cust = (from c in dc.Companies
                    where c.Id == companyId
                    select new CompanyEntity
                    {
                        Id = c.Id,
                        CompanyName = c.CompanyName
                    }).FirstOrDefault();

        return cust;
    }
}
Thanks again!

If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

GeneralRe: Write Async Method Pin
Richard Deeming1-Feb-21 0:02
mveRichard Deeming1-Feb-21 0:02 
GeneralRe: Write Async Method Pin
Kevin Marois1-Feb-21 8:36
professionalKevin Marois1-Feb-21 8:36 
GeneralRe: Write Async Method Pin
Richard Deeming1-Feb-21 21:20
mveRichard Deeming1-Feb-21 21:20 
QuestionHow to update members of a List using Linq? [Solved] Pin
Alex Dunlop26-Jan-21 23:54
MemberAlex Dunlop26-Jan-21 23:54 
AnswerRe: How to update members of a List using Linq? Pin
OriginalGriff27-Jan-21 0:15
mveOriginalGriff27-Jan-21 0:15 
GeneralRe: How to update members of a List using Linq? Pin
Alex Dunlop27-Jan-21 2:15
MemberAlex Dunlop27-Jan-21 2:15 
GeneralRe: How to update members of a List using Linq? Pin
OriginalGriff27-Jan-21 2:36
mveOriginalGriff27-Jan-21 2:36 
GeneralRe: How to update members of a List using Linq? Pin
Alex Dunlop27-Jan-21 3:04
MemberAlex Dunlop27-Jan-21 3:04 
GeneralRe: How to update members of a List using Linq? Pin
Richard Deeming27-Jan-21 4:10
mveRichard Deeming27-Jan-21 4:10 
GeneralRe: How to update members of a List using Linq? Pin
Dave Kreskowiak27-Jan-21 7:06
mveDave Kreskowiak27-Jan-21 7:06 
QuestionProper event handling in docked window schema Pin
gizbernus26-Jan-21 9:16
Membergizbernus26-Jan-21 9:16 
Questionalias names for Column in Linq Pin
simpledeveloper25-Jan-21 8:28
Membersimpledeveloper25-Jan-21 8:28 
AnswerRe: alias names for Column in Linq Pin
Gerry Schmitz25-Jan-21 10:18
mveGerry Schmitz25-Jan-21 10:18 
AnswerRe: alias names for Column in Linq Pin
Richard Deeming25-Jan-21 21:38
mveRichard Deeming25-Jan-21 21:38 
Questionhow to print POS bills with a thermal printer Pin
Meax24-Jan-21 8:53
MemberMeax24-Jan-21 8:53 
AnswerRe: how to print POS bills with a thermal printer Pin
Daniel Pfeffer24-Jan-21 9:23
professionalDaniel Pfeffer24-Jan-21 9:23 
GeneralRe: how to print POS bills with a thermal printer Pin
OriginalGriff24-Jan-21 10:25
mveOriginalGriff24-Jan-21 10:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.