Click here to Skip to main content
15,904,935 members
Home / Discussions / C#
   

C#

 
GeneralRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
OriginalGriff30-Jan-21 1:58
mveOriginalGriff30-Jan-21 1:58 
GeneralRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
arnold_w30-Jan-21 2:02
arnold_w30-Jan-21 2:02 
GeneralRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
OriginalGriff30-Jan-21 2:39
mveOriginalGriff30-Jan-21 2:39 
GeneralRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
arnold_w30-Jan-21 2:50
arnold_w30-Jan-21 2:50 
GeneralRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
OriginalGriff30-Jan-21 5:45
mveOriginalGriff30-Jan-21 5:45 
GeneralRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
Gerry Schmitz30-Jan-21 3:04
mveGerry Schmitz30-Jan-21 3:04 
JokeRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
Peter_in_278030-Jan-21 10:39
professionalPeter_in_278030-Jan-21 10:39 
GeneralRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
Gerry Schmitz30-Jan-21 12:29
mveGerry Schmitz30-Jan-21 12:29 
AnswerRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
Ralf Meier29-Jan-21 23:25
mveRalf Meier29-Jan-21 23:25 
GeneralRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
OriginalGriff29-Jan-21 23:57
mveOriginalGriff29-Jan-21 23:57 
GeneralRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
arnold_w30-Jan-21 0:40
arnold_w30-Jan-21 0:40 
AnswerRe: multi-comport receiver Pin
Luc Pattyn31-Jan-21 4:35
sitebuilderLuc Pattyn31-Jan-21 4:35 
QuestionWrite Async Method Pin
Kevin Marois27-Jan-21 6:37
professionalKevin Marois27-Jan-21 6:37 
AnswerRe: Write Async Method Pin
OriginalGriff27-Jan-21 8:07
mveOriginalGriff27-Jan-21 8:07 
GeneralRe: Write Async Method Pin
Kevin Marois27-Jan-21 8:37
professionalKevin Marois27-Jan-21 8:37 
GeneralRe: Write Async Method Pin
Victor Nijegorodov27-Jan-21 11:16
Victor Nijegorodov27-Jan-21 11:16 
GeneralRe: Write Async Method Pin
Pete O'Hanlon27-Jan-21 21:28
mvePete O'Hanlon27-Jan-21 21:28 
GeneralRe: Write Async Method Pin
Victor Nijegorodov27-Jan-21 22:35
Victor Nijegorodov27-Jan-21 22:35 
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 
Not really. Spinning up a new Task and awaiting it is only really useful if you want to move the processing onto a background thread. On the server, that doesn't make any sense.

On the server-side, you'd want to have async calls to the database. Entity Framework offers various async methods. Or, if you're using raw ADO.NET, use DbConnection.OpenAsync[^], DbCommand.ExecuteReaderAsync[^], etc.

On the client, you want the network call to be async, so that your code isn't blocked waiting for the network request to complete. If you're using HttpClient or RestClient, the default methods for calling the server will be async. If you're using WCF or HttpWebRequest, you might have to jump through a few hoops to make a nice async method.

You should generally avoid async void methods:
Avoid async void methods | You’ve Been Haacked[^]

Instead, follow David Fowler's advice[^] and store the Task returned from your async method in a discard variable:
C#
private void SaveExecuted()
{
    _ = SaveAsync();
}

private async Task SaveAsync()
{
    try
    {
        IServerAPI serverAPI = new ServerAPI();
        if (Company.Id == 0)
        {
            Company.Id = await serverAPI.AddCompanyAsync(Company);
        }
        else
        {
            await serverAPI.UpdateCompanyAsync(Company);
        }
    }
    finally
    {
        // Do post-save stuff here
    }
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

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 

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.