I suspect you can just change it to:
public Task PingAsync()
{
return Task.Factory.FromAsync(client.BeginPing, client.EndPing, new object());
}
There's no benefit in making this an async
method - you're just trying to create a task representing the async operation, and TaskFactory.FromAsync
does that for you.
If you really want to use async
and await
, just remove the return
part:
public async Task PingAsync()
{
await Task.Factory.FromAsync(client.BeginPing, client.EndPing, new object());
}
Looking at the overloads for FromAsync
I suspect you might want client.BeginPing()
instead of client.BeginPing
... and it's not clear why you're creating a new object
as the state instead of just using null
. Presumably you're not using that state...