Sto tentando di utilizzare Func con il metodo Async. E sto ottenendo un errore.Utilizzo del delegato Func con metodo Async
Impossibile convertire l'espressione lambda async per delegare il tipo
'Func<HttpResponseMesage>'
. Un'espressione lambda async può restituire void, Task oTask<T>
, nessuno dei quali è convertibile in'Func<HttpResponseMesage>'
.
di seguito è il mio codice:
public async Task<HttpResponseMessage> CallAsyncMethod()
{
Console.WriteLine("Calling Youtube");
HttpClient client = new HttpClient();
var response = await client.GetAsync("https://www.youtube.com/watch?v=_OBlgSz8sSM");
Console.WriteLine("Got Response from youtube");
return response;
}
static void Main(string[] args)
{
Program p = new Program();
Task<HttpResponseMessage> myTask = p.CallAsyncMethod();
Func<HttpResponseMessage> myFun =async() => await myTask;
Console.ReadLine();
}
Ho un post sul blog [tipi di delegati asincroni] (http://blog.stephencleary.com/2014/02/synchronous-and-asynchronous-delegate.html) che potresti trovare utile. –