public async Task <ValueModel> ResilentExternalCall(string id) { ValueServices service = new ValueServices(); using (CancellationTokenSource cts = new CancellationTokenSource()) { Task <ValueModel> serviceTask = service.GetValue(id, cts.Token); if (!Task.WaitAll(new Task[] { serviceTask }, 2000)) { cts.Cancel(); System.Diagnostics.Trace.TraceInformation("ResilentExternalCall: From Cache"); return(await Task.FromResult(CacheHelper.Get <ValueModel>(id))); } else { System.Diagnostics.Trace.TraceInformation("ResilentExternalCall: From Live"); return(await Task.FromResult(serviceTask.Result)); } } }
public async Task <string> ResilentExternalCall() { ValueServices service = new ValueServices(); using (CancellationTokenSource cts = new CancellationTokenSource()) { var serviceTask = service.GetValue(cts.Token); if (!Task.WaitAll(new Task[] { serviceTask }, 2000)) { cts.Cancel(); _logger.LogWarning("ResilentExternalCall: Overlimit"); return(await Task.FromResult("-1")); } else { _logger.LogDebug("ResilentExternalCall: From Live"); return(await Task.FromResult(serviceTask.Result.ToString())); } } }