Async Method in SignalR OnConnected()

.net, asynchronous, c#, signalr

Solution

But then I'm not returning anything. What's the right way to do this?

You don't need to return anything. `async Task` is the asynchronous equivalent of (synchronous) `void`. `Task` means there's no return value, so your code is already correct.

Put another way: `async` will construct the returned `Task`/`Task<T>` for you. So if your method does not have `async` (as in your first example), you need to return a task; but if your method does have `async` (as in your second example), then you don't.

Problem

I have the following: ``` public override Task OnConnected() { HandleConnectionAsync(Context).Wait(); return base.OnConnected(); } ``` In following the guidance around "don't block a hub method", I'm trying to await my `HandleConnectionAsync` call, but if I use `async`, I end up with the following: ``` public override async Task OnConnected() { await HandleConnectionAsync(Context); await base.OnConnected(); } ``` But then I'm not returning anything. What's the right way to do this?

Original source