How would I create a lambda expression for a task that returns a string?
This is what I have tried but I get an error.
Thank you for any help.
public static async Task<string> GetStringAsync(string path)
{
try
{
var task = new Task<string>(async () =>
{
var response = await Client.GetAsync(path);
var responsestring = await response.Content.ReadAsStringAsync();
return responsestring;
});
return await Task.WhenAny(task, Task.Delay(20000)) == task
? task.Result
: RequestTimeOutMessage;
}
catch (Exception e)
{
return e.GetBaseException().Message;
}
}
}