public async Task RetryExecAsyncTest() { try { await PolicyHelper.RetryExecAsync <DivideByZeroException>(async() => { Console.WriteLine("func........."); throw new DivideByZeroException(); }); } catch (Exception ex) { } Assert.Pass(); }
public static async Task <string> getTokenAsync(string strURL, string strContent, string mediaType, int RetryCount = 3) { string strToken = string.Empty; await limitLock.WaitAsync().ConfigureAwait(false); try { using (var client = new HttpClient()) { using (var content = new StringContent(strContent, Encoding.UTF8, mediaType)) { await PolicyHelper.RetryExecAsync <TokenException>(async() => { try { var response = await client.PostAsync(strURL, content); response.EnsureSuccessStatusCode(); var responseStr = await response.Content.ReadAsStringAsync(); if (responseStr.Contains("access_token")) { var temp = JsonConvert.DeserializeObject <dynamic>(responseStr); strToken = temp.access_token; } else { throw new TokenException(); } } catch (Exception ex) { throw new TokenException(ex.Message, ex); } }); } } } catch (TokenException ex) { Console.WriteLine($"Excepiton:{ex.Message}"); } finally { limitLock.Release(); } return(strToken); }
public async Task <string> SendRequest(HttpClient httpClient, string strURL, Dictionary <string, string> queryParam, int RetryCount = 3) { string result = string.Empty; try { await PolicyHelper.RetryExecAsync <TokenException>(async() => { result = await SendRequest(httpClient, strURL, queryParam); }); } catch (Exception ex) { Console.WriteLine($"Excepiton:{ex.Message}"); } return(result); }