Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var generalExceptionPolicy=Policy.Handle<Exception>().WaitAndRetry(2, retryAttempt =>
- TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),(exception,timespan)=>{
- if(attempt++ == 2)
- {
- Toast.MakeText(Activity,"No Connection Bro",ToastLength.Short).Show();
- }
- });
- var test = await generalExceptionPolicy.ExecuteAsync(()=>PostPreLogin (view.FindViewById<EditText> (Resource.Id.mobileTextBox).Text));
- public async Task<string> PostPreLogin(string userName)
- {
- var preloginvalue = await Account.PreLoginPost (userName);
- return preloginvalue;
- }
- generalExceptionPolicy.ExecuteAndCapture(() => DoSomething());
- async Task<HttpResponseMessage> QueryCurrencyServiceWithRetryPolicy(Func<Task<HttpResponseMessage>> action)
- {
- int numberOfTimesToRetry = 7;
- int retryMultiple = 2;
- //Handle HttpRequestException when it occures
- var response = await Policy.Handle<HttpRequestException>(ex =>
- {
- Debug.WriteLine("Request failed due to connectivity issues.");
- return true;
- })
- //wait for a given number of seconds which increases after each retry
- .WaitAndRetryAsync(numberOfTimesToRetry, retryCount => TimeSpan.FromSeconds(retryCount * retryMultiple))
- //After the retry, Execute the appropriate set of instructions
- .ExecuteAsync(async () => await action());
- //Return the response message gotten from the http client call.
- return response;
- }
- var response = await QueryCurrencyServiceWithRetryPolicy(() => _httpClient.GetAsync(ALL_CURRENCIES_URL));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement