Is there a way to wait for a task to end but move on after a certain period of time but let the task itself continue on? I would like a response back from a task within 5 seconds and don't want to wait longer than that -- however, if longer than 5 seconds have passed, I just want to move on and not actually cancel the task (ruling out cancellation tokens).
I'm using .NET Core / C#.
private async Task<string> MakeAuthRequest(Request request)
{
try
{
var response = await SometimesLongMethod(request); // something needs to be done here, just not sure what
return response.Message;
}
catch(Exception e)
{
logger.Error(e, "Error occurred");
return string.Empty;
}
}