© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
50 replies
Pannekoekje

Async await in minimal API

Hey guys, I have a minimal API app which also hosts a client which has a websocket connection.
The websocket gets in a disconnect state a lot so I reconnect if I can't get the data I want.

However, it seems like the await for the reconnect isn't properly awaited, is there some special async/await mechanics in these minimal API routed calls?

Code:

app.MapGet("/account", async Task<Results<Ok<AccountOverview>, NoContent>>
    () =>
    {
        try
        {
            await _client.GetAccount();
        }
        catch
        {
            _client.Reconnect().Wait();
            await _client.Authenticate();
            await _client.GetAccount();
        }
    ...
    }
);
app.MapGet("/account", async Task<Results<Ok<AccountOverview>, NoContent>>
    () =>
    {
        try
        {
            await _client.GetAccount();
        }
        catch
        {
            _client.Reconnect().Wait();
            await _client.Authenticate();
            await _client.GetAccount();
        }
    ...
    }
);

I've tried with both .Wait and await for the reconnect call.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

Async/Await question
C#CC# / help
2w ago
Using async,await in old codebase
C#CC# / help
4y ago
✅ async/await and parallelism
C#CC# / help
13mo ago
async/await and mutexes
C#CC# / help
2y ago